[rspec-devel] [ rspec-Bugs-5539 ] predicates do not work w/ rails

noreply at rubyforge.org noreply at rubyforge.org
Thu Oct 26 07:55:44 EDT 2006


Bugs item #5539, was opened at 2006-08-27 14:24
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=5539&group_id=797

Category: None
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: David Chelimsky (dchelimsky)
Assigned to: Nobody (None)
Summary: predicates do not work w/ rails

Initial Comment:
Instead of doing:

       @dave.tracks.should_include Track.find_by_name("School's Out")

I have to do:

       @dave.tracks.include?(Track.find_by_name("School's Out")).should_be
true



----------------------------------------------------------------------

Comment By: Aslak Hellesoy (aslak_hellesoy)
Date: 2006-09-06 05:56

Message:
Jeff,

It seems to me that the error message you're getting from rails is different than the one David and I are getting.

I think you found a new bug. Can you file a separate ticket please?

----------------------------------------------------------------------

Comment By: Jeff Hoffman (wheeledone)
Date: 2006-09-06 02:27

Message:
I can confirm this behavior with a has_many:

class Context < AR::B
  has_many :items
end

class Items < AR::B
  belongs_to :context
end

context "A new context" do
  setup do
    @context = Context.new
  end

  specify "should not have any items" do
    @context.action_items.should_be_empty
  end
end

Fails, saying 'empty?' is not available on ActionItem:Class.

if I use should_satisfy, it works:

@context.should_satisfy { |c| c.items.empty? }

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-08-29 22:33

Message:
Yep. Same thing.

----------------------------------------------------------------------

Comment By: Aslak Hellesoy (aslak_hellesoy)
Date: 2006-08-29 12:12

Message:
I have added a spec for this in rspec_on_rails' person_spec.rb. It gives me:

1)
TypeError in 'The Person model should include animals'
wrong argument type Animal (expected Module)
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1129:in `method_missing'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:102:in `method_missing'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:873:in `with_scope'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:92:in `method_missing'
./spec/models/person_spec.rb:23:in `should include animals'
/Users/aslakhellesoy/scm/rspec/trunk/vendor/rspec_on_rails/config/../vendor/plugins/rspec/lib/rspec_on_rails.rb:103:in `run'

Finished in 0.545273 seconds

5 specifications, 1 failure
rake aborted!

Is that what you get?

For now I have commented out the spec, but at least we have a starting point.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-08-27 14:25

Message:
I *THINK* that this is a conflict between method_missing as used by should_helper and that of active_record. If correct, we solved this for sugar's use of method_missing and should be able to either reuse or duplicate that effort for should_helper.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=5539&group_id=797


More information about the rspec-devel mailing list