views:

70

answers:

1

I'm trying out 'shoulda' on top of rspec (rails 3) with the following spec:

require 'spec_helper'
describe Article do
  should "be true" do
    assert true
  end
end

and it fails with

/Users/jeppe/.rvm/gems/ruby-1.8.7-p302/gems/rspec-expectations-2.0.0.beta.20/lib/rspec/expectations/handler.rb:11:in `handle_matcher': undefined method `matches?' for "be true":String (NoMethodError)

Now my tests will run just fine when I do both

require 'spec_helper'
describe Article do
  it "should be true" do
    assert true
  end
end

and

require 'spec_helper'
describe Article do
  it { should belong_to :issue }
  it { should have_and_belong_to_many :pages }
  it { should have_many :tasks }
end

where the last uses Shoulda::ActiveRecord::Matchers, so to my knowledge shoulda is loaded allright.

Any suggestions?

+1  A: 

In RSpec should is an RSpec method used to trigger a matcher - it is not Shouldas context block. For that, you use RSpecs own describe.

should "be true" do
  assert true
end

is Shoulda's Test::Unit based syntax, which shouldn't work in RSpec examples (I guess?). Just use your second example, which has the same effect and the right syntax.

Jakob S
Ok, so I was 'just' confused with Test::Unit vs Rspec syntax - thanks for pointing that out :-)
Jeppe Liisberg