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
end

I'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)

Re: [Solved] Beginning with RSpec

Try removing the

Re: [Solved] Beginning with RSpec

jasnow wrote:

Try removing the

I think that missing the end of message.

But if you ask to remove the eq and replace it by ==, the test pass.

I think one dependancy is missing for the matchers...

Re: [Solved] Beginning with RSpec

I don't understand, I was testing :

 defined?(::RSpec::Matchers)

and now the tests pass.


I have created again a new project with different objects, and now tests pass...

Sorry for the inconvenience.