Topic: [Solved] Beginning with RSpec
Hi,
I try to discover RSpec for Rails. I'm usin Rails 3.2 and RSpec 2.10. I've generated one project with one scaffold Post which have 2 attributes title:string and body:text.
RSpec have generated tests with scaffold. I've commented all controller test except the first when I run
bundle exec rake spec:controllers, I get :
F
Failures:
1) PostsController GET index assigns all posts as @posts
Failure/Error: assigns(:posts).should eq([post])
NoMethodError:
undefined method `eq' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f9f4ee83ec0>
# ./spec/controllers/posts_controller_spec.rb:41:in `block (3 levels) in <top (required)>'
Finished in 0.03367 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/controllers/posts_controller_spec.rb:38 # PostsController GET index assigns all posts as @posts
rake aborted!My controller test have this code:
require 'spec_helper'
describe PostsController, :type => :controller do
def valid_attributes
{ :title => "Test", :body => "Hello World"}
end
def valid_session
{}
end
describe "GET index" do
it "assigns all posts as @posts" do
post = Post.create! valid_attributes
get :index, {}, valid_session
assigns(:posts).should eq([post])
end
end
endI've searched on Internet but i didn't found any solutions.
Someone have idea of my problem?
Thanks.
Last edited by GRoguelon (2012-05-04 15:43:02)