Question

I am using rspec version 2.14.8 and Ruby 2.1.1.

I have the following in test_spec.rb

describe 'My code' do
  it 'should work' do
    expect ( nil ).to be_nil
    expect ( "test" ).to eq( "test")
  end
end

When I run this simple spec (rspec test_spec.rb), I get the following error:

Failures:

 1) My code should work
    Failure/Error: expect ( nil ).to be_nil
    NoMethodError:
      undefined method `to' for nil:NilClass
    # ./test_spec.rb:3:in `block (2 levels) in <top (required)>'

What is wrong!?

Was it helpful?

Solution

You must not put a space between expect and the opening paren (.

The working code sample is as follows:

describe 'My code' do
  it 'should work' do
    expect( nil ).to be_nil
    expect( "test" ).to eq( "test")
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top