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
Naomi Freeman
Treehouse Guest TeacherRSpec weirdness - Rails ToDo App
Sorry. Already posted this but never got a response because I accidentally "answered" my question instead of adding comments.
I know something is wrong with my “end”s. I just have one at the end of each test, but when I ran each individual test in the terminal, it was throwing an error of something like “unexpected end … etc.” So I just added “end” at the very end of the document. It kept throwing the same error with each test … so I just kept adding end. I knew this was probably not good, but I didn’t know where I was supposed to put them.
My biggest concern is, as you’ll see at the end of this error, it’s only seeing 2 tests, when there are clearly more than that.
All my validations are complete, so my tests shouldn’t be throwing any errors anymore.
I should have 5 examples, 0 failures. Instead, I have 2 examples, 1 failure.
With the below tests (following the error), I’m getting this in my Terminal:
vagrant@precise64:~/hacker_you/projects/odot$ rspec spec/features/todo_lists/create_spec.rb
/home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in load': /vagrant/projects/odot/spec/features/todo_lists/create_spec.rb:97: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:inblock in load_spec_files'
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in each'
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:inload_spec_files'
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in run'
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:inrun'
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in block in autorun'
vagrant@precise64:~/hacker_you/projects/odot$ rspec spec/features/todo_lists/create_spec.rb
/home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:inload': /vagrant/projects/odot/spec/features/todo_lists/create_spec.rb:97: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in block in load_spec_files'
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:ineach'
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in load_spec_files'
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:inrun'
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in run'
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:inblock in autorun'
vagrant@precise64:~/hacker_you/projects/odot$ rspec spec/features/todo_lists/create_spec.rb
.F
Failures:
1) Creating todolists displays an error when the todo list has no title
Failure/Error: it "redirects to the todo list index page on success" do
NoMethodError:
undefined method it' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f70e8e35c00>
# ./spec/features/todo_lists/create_spec.rb:19:inblock (2 levels) in <top (required)>'
Finished in 0.43786 seconds 2 examples, 1 failure
Failed examples:
rspec ./spec/features/todo_lists/create_spec.rb:16 # Creating todolists displays an error when the todo list has no title
Randomized with seed 58507
require 'spec_helper'
describe "Creating todolists" 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 list"
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)
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: ""
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
it "displays an error when the todo list has a title less than 3 characters" do
expect(TodoList.count).to eq(0)
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: ""
fill_in "Description", with: "Hi"
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
it "displays an error when the todo list has no description" do
expect(TodoList.count).to eq(0)
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: "Grocery list"
fill_in "Description", with: ""
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("Grocery list")
end
it "displays an error when the todo list has a description less than 5 characters" do
expect(TodoList.count).to eq(0)
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: "Grocery list"
fill_in "Description", with: "Food"
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 end end end end
How do I fix it?
Please note because my code is hilariously wrong, it doesn't auto put in the black box all of the code. My test code is everything from "require" to the final of all of those "end"s.
Naomi Freeman
Treehouse Guest Teacher!Attention Treehouse:
Now I'm completing the module "Creating methods with tests" and the code in the video is not the same as the code we just wrote.
It has 2 "displays an error when the todo list has no description" and misses "displays an error when the todo list has a title less than 3 characters".
Additionally, I found the extra "examples" are coming out of this line:
it "redirects to the todo list index page on success" do
which was after expect... and before the whole chunk of code we just turned into a method.
For now I have commented out the "redirects to the todo list index page on success".
I'm down to 5 examples, no errors.
My stuff is running. It's just inconsistent in the tutorials and wanted to point that out.
1 Answer
Jason Seifer
Treehouse Guest TeacherHi Naomi Freeman there's a lot going on here and the formatting makes it a bit hard to read. Please drop a line to help@teamtreehouse.com if you're still having trouble.
Naomi Freeman
Treehouse Guest TeacherOk. I will email you guys a bit later :) I am out of the boiling water. There is some weird stuff happening in the tutorial though. Talk soon.
Naomi Freeman
Treehouse Guest TeacherNaomi Freeman
Treehouse Guest TeacherFound someone on twitter and the below works. However, it comes up with 9 examples and 0 failures, while the tutorial says I should be at 5 examples and 0 failures. Any idea why this difference? It was explained to me that a new block occurs every time 'it' or 'describes' happens.
This is working and not throwing errors, but why does it differ from the tutorial? Just curious. Thanks!
require 'spec_helper'
describe "Creating todolists" 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")
end