Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Write Our First Tests

Aaron Butler
Aaron Butler
2,655 Points

Why am I getting test failures when I run bin/rspec spec/features/todo_lists/create_spec.rb?

$ bin/rspec spec/features/todo_lists/create_spec.rb
FF

Failures:

  1) Creating Todo lists redirects to the Todo list index page on success
     Failure/Error: visit "/todo_lists"
     SyntaxError:
       C:/Users/Doesha/desktop/projects/odot/app/models/todo_list.rb:2: syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '('
        validates :title, presence :true
                                    ^
     # ./app/controllers/todo_lists_controller.rb:7:in `index'
     # ./spec/features/todo_lists/create_spec.rb:5:in `block (2 levels) in <top (required)>'

  2) Creating Todo lists displays an error when the todo list has no title
     Failure/Error: expect(TodoList.count).to eq(0)
     SyntaxError:
       C:/Users/Doesha/desktop/projects/odot/app/models/todo_list.rb:2: syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '('
        validates :title, presence :true
                                    ^
     # ./spec/features/todo_lists/create_spec.rb:17:in `block (2 levels) in <top (required)>'

Finished in 0.09355 seconds
2 examples, 2 failures

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:4 # Creating Todo lists redirects to the Todo list index page on success
rspec ./spec/features/todo_lists/create_spec.rb:16 # Creating Todo lists displays an error when the todo list has no title

Randomized with seed 56798

17 Answers

Can you post you todo_list.rb please.

I think you have:

validates :title, presence :true

It should be

validates :title, presence: true

Move the colon.

Steve.

Two issues here - both are in create_spec.rb.

The second test is failing due to a typo - your failure says: undefined method `cilck_button' - just correct the spelling.

The first issue is down to the test not correlating to the page. The failures can be really descriptive (they can also be wholly unhelpful!!). This one is OK - it is saying that your test is expecting the page to have the content "New todo_list" but it is finding (correctly in my view) "New Todo List". Your test is wrong, in my opinion.

Change the code in create_spec.rb from:

expect(page).to have_content("New todo_list")

to

expect(page).to have_content("New Todo List")

That reflects what you are trying to test. This may just flush out another failure - that's good; this is how test driven development works.

The bit of the error that explains that is:

expect(page).to have_content("New todo_list") expected to find text "New todo_list" in "New Todo List Title Description Back"

Hope that helps!

Steve.

Never come across that before but it looks like it makes the console look better and to query the terminal: https://rubygems.org/gems/win32console/versions/1.3.2

I'd put it outside of any groups in the Gemfile. As for using it, I don't know - where have you come across this? What said you need to include it?

Steve.

Aaron Butler
Aaron Butler
2,655 Points

Well, I came across this message while I was doing the Rails tutorial by Michael Hartl. I apologize for the question not pertaining to a treehouse track, but I'm learning from different resources and I'm just trying to tie everything all together. It's a lot of information for me to grasp at once, but I think I'll get it eventually.

Thanks for all your help so far!

I've covered most of that book but didn't come across that. I must dedicate more time to it; I've not done any decent coding in ages.

Did you also correct the inconsistency between:

click_button "Create Todo lists"

and

click_button "Create Todo list"

as I think that was the cause of the error: Capybara::ElementNotFound: Unable to find button "Create Todo lists" as it was looking for the plural when only the singular existed.

Glad you got on your way.

Steve.

Hi Aaron,

A deprecation is where the functionality you are using has been superceded by something better. The thing you're using still works, which is why you get a warning not an error, but there may be a better way of doing that in the later version of the various chunks of software that make up Ruby on Rails

Unless you're really wanting rid of the warnings, just ignore them. The errors themselves usually give you instructions on how to suppress them Best just ignore, though - don't worry about them.

You have no failures in there - which is one hell of an achievement! This course is a tricky one!

Steve.

Aaron Butler
Aaron Butler
2,655 Points

I changed my todo list around to the second part of your answer, but I'm still getting test failures. I am on a Windows 10 OS so that might be the problem! Here's my todo_list.rb file:

class TodoList < ActiveRecord::Base
    validates :title, presence: true
end

I'm still getting the same results which is a failed test. Here is my output:

$ bin/rspec spec/features/todo_lists/create_spec.rb
FF

Failures:

  1) Creating Todo lists displays an error when the todo list has no title
     Failure/Error: expect(page).to have_content("New todo_list")
       expected to find text "New todo_list" in "New Todo List Title Description Back"
     # ./spec/features/todo_lists/create_spec.rb:21:in `block (2 levels) in <top (required)>'

  2) Creating Todo lists redirects to the Todo list index page on success
     Failure/Error: cilck_button "Create Todo lists"
     NoMethodError:
       undefined method `cilck_button' for #<RSpec::Core::ExampleGroup::Nested_1:0x742f620>
     # ./spec/features/todo_lists/create_spec.rb:11:in `block (2 levels) in <top (required)>'

Finished in 1.29 seconds
2 examples, 2 failures

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:16 # Creating Todo lists displays an error when the todo list has no title
rspec ./spec/features/todo_lists/create_spec.rb:4 # Creating Todo lists redirects to the Todo list index page on success

Randomized with seed 744

Any idea what could be the reason I'm having a result of failing test?

This is progress!; it isn't the same result - you've moved away from a syntax error to an actual failed test. Let me boot the laptop and I'll have a look at why the failure happened. :-)

Aaron Butler
Aaron Butler
2,655 Points

Hey Steve,

I've gotten rid of one failed test and I appreciate your help with that one; but I'm still getting another failed test. I'm assuming this is the test you stated that would fail previously in your response answers above.

Here is the output from the failed test I've just gotten:

$ bin/rspec spec/features/todo_lists/create_spec.rb
F.

Failures:

  1) Creating Todo lists redirects to the Todo list index page on success
     Failure/Error: click_button "Create Todo lists"
     Capybara::ElementNotFound:
       Unable to find button "Create Todo lists"
     # ./spec/features/todo_lists/create_spec.rb:11:in `block (2 levels) in <top (required)>'

Finished in 0.8416 seconds
2 examples, 1 failure

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:4 # Creating Todo lists redirects to the Todo list index page on success

Randomized with seed 37526

Is this something involving the Capybara gem not being up-to-date? Could it be another syntax error somewhere?

Here's my create_spec.rb file:

require 'spec_helper'

describe "Creating Todo lists" do 
    it "redirects to the Todo list index page on success" do
        visit "/todo_lists"
        click_link "New Todo list"
        expect(page).to have_content("New Todo List")

        fill_in "Title", with: "My todo list"
        fill_in "Description", with: "This is what I'm doing today."
        click_button "Create Todo lists"

        expect(page).to have_content("My todo List")
    end

    it "displays an error when the todo list has no title" do
        expect(TodoList.count).to eq(0)

        visit "/todo_lists"
        click_link "New Todo list"
        expect(page).to have_content("New Todo List")

        fill_in "Title", with: ""
        fill_in "Description", with: "This is what I'm doing today."
        click_button "Create Todo list"

        expect(page).to have_content("error")
        expect(TodoList.count).to eq(0)

        visit "/todo_lists"
        expect(page).to_not have_content("This is what I'm doing today.")
    end 
end

I'm out at the moment but can see the problem. Give me an hour or so and I'll get to you.

Your page is missing a button called Create Too lists. Do you have a button?

Aaron Butler
Aaron Butler
2,655 Points

Hey Steve,

I found the problem!

My test code

expect(page).to have_content("My todo List")

and

fill_in "Title", with: "My todo list"

wasn't consistent in their syntax.

I just had to make sure everything matched up like you stated before.

Thanks for your help!

Aaron

Great work!

Give me a shout if you run into any other issues.

Steve.

Aaron Butler
Aaron Butler
2,655 Points

Yes, I did correct the inconsistency between

click_button "Create Todo lists"

and

click_button "Create Todo list"

I'll definitely give you a shout out if I run across any more problems!

Aaron Butler
Aaron Butler
2,655 Points

Hey Steve,

I just ran the command

bin/rake spec

and it's saying that I have Deprecation Warnings. What are Deprecation's and how can I get rid of them?

Here's the output I got:

..*.*....................DEPRECATION WARNING: `named_routes.helpers` is deprecated, please use `route_defined?(route_name)` to see if a named route was defined. (called from block (4 levels) in <top (required)> at C:/Users/Doesha/desktop/projects/odot/spec/controllers/todo_lists_controller_spec.rb:75)
.....DEPRECATION WARNING: `named_routes.helpers` is deprecated, please use `route_defined?(route_name)` to see if a named route was defined. (called from block (3 levels) in <top (required)> at C:/Users/Doesha/desktop/projects/odot/spec/controllers/todo_lists_controller_spec.rb:156)
..

Pending:
  TodoListsHelper add some examples to (or delete) C:/Users/Doesha/desktop/projects/odot/spec/helpers/todo_lists_helper_spec.rb
    # No reason given
    # ./spec/helpers/todo_lists_helper_spec.rb:14
  TodoList add some examples to (or delete) C:/Users/Doesha/desktop/projects/odot/spec/models/todo_list_spec.rb
    # No reason given
    # ./spec/models/todo_list_spec.rb:4

Deprecation Warnings:

--------------------------------------------------------------------------------
The semantics of `RSpec::Core::ExampleGroup.pending` are changing in RSpec 3.
In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
still be run but is expected to fail, and will be marked as a failure (rather
than as pending) if the example passes, just like how `pending` with a block
from within an example already works.

To keep the same skip semantics, change `pending` to `skip`.  Otherwise, if you
want the new RSpec 3 behavior, you can safely ignore this warning and continue
to upgrade to RSpec 3 without addressing it.

Called from C:/Users/Doesha/desktop/projects/odot/spec/helpers/todo_lists_helper_spec.rb:14:in `block in <top (required)>'.

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
The semantics of `RSpec::Core::ExampleGroup.pending` are changing in RSpec 3.
In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
still be run but is expected to fail, and will be marked as a failure (rather
than as pending) if the example passes, just like how `pending` with a block
from within an example already works.

To keep the same skip semantics, change `pending` to `skip`.  Otherwise, if you
want the new RSpec 3 behavior, you can safely ignore this warning and continue
to upgrade to RSpec 3 without addressing it.

Called from C:/Users/Doesha/desktop/projects/odot/spec/models/todo_list_spec.rb:4:in `block in <top (required)>'.

--------------------------------------------------------------------------------

`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from C:/Users/Doesha/desktop/projects/odot/spec/views/todo_lists/index.html.erb_spec.rb:6:in `block (2 levels) in <top (required)>'.
`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from C:/Users/Doesha/desktop/projects/odot/spec/views/todo_lists/index.html.erb_spec.rb:10:in `block (2 levels) in <top (required)>'.
`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from C:/Users/Doesha/desktop/projects/odot/spec/views/todo_lists/new.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'.
Too many uses of deprecated '`stub_model`'. Pass `--deprecation-out` or set `config.deprecation_stream` to a file for full output.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

7 deprecation warnings total

Finished in 3.57 seconds
32 examples, 0 failures, 2 pending

Randomized with seed 35934

C:/RailsInstaller/Ruby2.1.0/bin/ruby.exe -S rspec ./spec/controllers/todo_lists_controller_spec.rb ./spec/features/todo_lists/create_spec.rb ./spec/helpers/todo_lists_helper_spec.rb ./spec/models/todo_list_spec.rb ./spec/requests/todo_lists_spec.rb ./spec/routing/todo_lists_routing_spec.rb ./spec/views/todo_lists/edit.html.erb_spec.rb ./spec/views/todo_lists/index.html.erb_spec.rb ./spec/views/todo_lists/new.html.erb_spec.rb ./spec/views/todo_lists/show.html.erb_spec.rb
Aaron Butler
Aaron Butler
2,655 Points

Hey Steve,

Thanks for clearing up that deprecation thing for me, I really appreciate that!

I did have another question though; can you tell me what this means:

ansi: 'gem install win32console' to use color on Windows

I'm assuming that this gem is needed somewhere in my gem file to help me get color on my command line. I'm not sure about how to use it or where exactly should I put it in my gem file though.

Aaron Butler
Aaron Butler
2,655 Points

Well, it was demonstrated by Michael Hartl in the screencast videos, so that maybe why you probably didn't come across it when you were reading the book.

Are the videos good? Worth a watch?

Aaron Butler
Aaron Butler
2,655 Points

Yes, they are very good and definitely worth the watch! Gives you a lot of clarification on different ways and techniques you can use that can't be explained and understood clearly to the average beginner through text. In my opinion, they're the best tutorial videos I've seen so far!

Aaron Butler
Aaron Butler
2,655 Points

Hey Steve,

I'm trying to add a feature to my rails project where users can upload an audio file. To do that, should I create a new model for the audio files or can I just add to an existing model I already have? I have my app set up already where a user can upload an image, but I'm not to sure how I can have the user upload an audio file also.

Do you think you can help me out with that? I have my code up on Github also if you would like to check it out!

Aaron Butler
Aaron Butler
2,655 Points

Okay, thanks Steve! That actually makes a lot of sense to make a separate model instead of adding onto an existing model. Thanks for giving me a clearer understanding!

Difficult to answer that - what is the app? Do you have it running in Heroku, for example?

A Model should be introduced for something new and distinct. It's almost like a class in Java, for example.

So, a User has a model. If you remember in the Todo list app, each todo item was a model and each todo list was a model. They are distinct things in that usage.

What will the audio file be doing in your app?

I don't think it would ever be wrong to create a new model for this - it might not be wholly efficient - but I'd say you can develop the functionality more easily if it were a separate model, rather than expanding the existing model to cope with audio-only requirements, if that makes sense?

Hope that helps but I suspect you're better at Rails than I am!!

Steve.

Aaron Butler
Aaron Butler
2,655 Points

Hello Steve,

How can I delete a migration file by the migration id number? I don't really understand the rollback migration command to well and the migration file I want to delete wasn't my last migration created. It was created a couple migrations before my last migration.

Thanks,

Aaron

I really don't know - sorry! Definitely worth having a Google around for that. The usual rake db:rollback works fine, but I'm not sure how that would work when there's another migration after it. Good luck!!