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 trialSeth Reece
32,867 PointsDifferent code showing in todo_list_controller_spec.rb
Above where we edit :valid_attributes my file says
RSpec.describe TodoListsController, :type => :controller do
as compared to
describe TodoListsController do
probably a difference in rspec versions?
the other part though is the part we edit I have
let(:valid_attributes) {
skip("Add a hash of attributes valid for your model")
}
let(:invalid_attributes) {
skip("Add a hash of attributes invalid for your model")
}
if I change to read the same as lesson file,
let(:valid_attributes) { { "title" => "MyString", "description" => "My Description" } }
I get this response from rake spec
......*..........*..FF...FF....*.....F...
Pending:
TodoListsHelper add some examples to (or delete) /home/treehouse/projects/odot/spec/helpers/todo_lists_helper
_spec.rb
# No reason given
# ./spec/helpers/todo_lists_helper_spec.rb:14
TodoListsController PUT update with valid params updates the requested todo_list
# Add a hash of attributes valid for your model
# ./spec/controllers/todo_lists_controller_spec.rb:103
TodoList add some examples to (or delete) /home/treehouse/projects/odot/spec/models/todo_list_spec.rb
# No reason given
# ./spec/models/todo_list_spec.rb:4
Failures:
1) TodoListsController PUT update with invalid params assigns the todo_list as @todo_list
Failure/Error: put :update, {:id => todo_list.to_param, :todo_list => invalid_attributes}, valid_session
NameError:
undefined local variable or method `invalid_attributes' for #<RSpec::Core::ExampleGroup::Nested_1::Neste
d_6::Nested_2:0xbb3cd30c>
# ./spec/controllers/todo_lists_controller_spec.rb:126:in `block (4 levels) in <top (required)>'
2) TodoListsController PUT update with invalid params re-renders the 'edit' template
Failure/Error: put :update, {:id => todo_list.to_param, :todo_list => invalid_attributes}, valid_session
NameError:
undefined local variable or method `invalid_attributes' for #<RSpec::Core::ExampleGroup::Nested_1::Neste
d_6::Nested_2:0xbb3d5b10>
# ./spec/controllers/todo_lists_controller_spec.rb:132:in `block (4 levels) in <top (required)>'
3) TodoListsController POST create with invalid params assigns a newly created but unsaved todo_list as @todo
_list
Failure/Error: post :create, {:todo_list => invalid_attributes}, valid_session
NameError:
undefined local variable or method `invalid_attributes' for #<RSpec::Core::ExampleGroup::Nested_1::Neste
d_5::Nested_2:0xbb40877c>
# ./spec/controllers/todo_lists_controller_spec.rb:86:in `block (4 levels) in <top (required)>'
4) TodoListsController POST create with invalid params re-renders the 'new' template
Failure/Error: post :create, {:todo_list => invalid_attributes}, valid_session
NameError:
undefined local variable or method `invalid_attributes' for #<RSpec::Core::ExampleGroup::Nested_1::Neste
d_5::Nested_2:0xbb40d9e8>
# ./spec/controllers/todo_lists_controller_spec.rb:91:in `block (4 levels) in <top (required)>'
5) TodoLists GET /todo_lists works! (now write some real specs)
Failure/Error: expect(response).to have_http_status(200)
NoMethodError:
undefined method `has_http_status?' for #<ActionDispatch::TestResponse:0xbb40c624>
# ./spec/requests/todo_lists_spec.rb:7:in `block (3 levels) in <top (required)>'
Failed examples:
rspec ./spec/controllers/todo_lists_controller_spec.rb:124 # TodoListsController PUT update with invalid params assigns the todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:130 # TodoListsController PUT update with invalid params re-renders the 'edit' template
rspec ./spec/controllers/todo_lists_controller_spec.rb:85 # TodoListsController POST create with invalid params assigns a newly created but unsaved todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:90 # TodoListsController POST create with invalid params re-renders the 'new' template
rspec ./spec/requests/todo_lists_spec.rb:5 # TodoLists GET /todo_lists works! (now write some real specs)
3 Answers
Maciej Czuchnowski
36,441 PointsAre you using the newest version of RSpec, i.e. above 3.0? The videos use version 2.14 (or something similar) and there were some major syntax and behavior changes between versions 2 and 3, so this might be the cause.
Seth Reece
32,867 PointsIt says I'm on version 2.99.2 if I run bin/rspec -v
Amanda Folson
1,050 PointsPart of it can be fixed with this:
let(:valid_attributes) {
{
"title" => "My String",
"description" => "My Description"
}
}
It also wants a hash of "invalid attributes" for these tests but I'm not sure what that means exactly.
You'll likely get a few more "pending" tests after fixing that, unfortunately.
steven alston
16,292 PointsI put in this block for the invalid attributes, which cleared most of the pending items in the rake spec test.
let(:invalid_attributes) {
{
"title" => "",
"description" => ""
}
}
It also asked for PUT update :new_attributes and assertions. Still trying to google this, any ideas?
describe "PUT update" do
describe "with valid params" do
let(:new_attributes) {
{}
}
it "updates the requested todo_list" do
todo_list = TodoList.create! valid_attributes
put :update, {:id => todo_list.to_param, :todo_list => new_attributes}, valid_session
todo_list.reload
skip("Add assertions for updated state")
end