[cucumber] Tests pass, application does not

This has just cropped up this morning and I have no clue as to what is
causing it.

Here is the error when running the application through the web browser
in development:

undefined method `method_exists?’ for #Entity:0x2b7214243bd0

/usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/attribute_methods.rb:255:in
method_missing' /home/byrnejb/Software/Development/Projects/proforma.git/lib/hll_attr_set_by_names.rb:16:inattr_set_by_names’

Here is the code:

14 an.each do |f|
15 puts “checking method: #{f}”
16 self.send("#{f}=", “#{param_hash[f]}”) if
self.method_exists?("#{f}=")
17 end

But, when I run the cucumber test for the same controller and view this
is what I see:

And they enter the entity legal name “MyUser LEGAL NAME”
#
features/app/models/entities/step_definitions/entity_steps.rb:66
entity_common_name
entity_legal_name
entity_legal_form
checking method: entity_common_name
checking method: entity_legal_name
checking method: entity_legal_form
And I press “Create”
# features/support/step_definitions/local_webrat_steps.rb:14
Then they should see a save error message
# features/app/step_definitions/crud_response_steps.rb:24

12 scenarios
78 passed steps

I am lost… Help?

James B. wrote:

This has just cropped up this morning and I have no clue as to what is
causing it.

Here is the error when running the application through the web browser
in development:

undefined method `method_exists?’ for #Entity:0x2b7214243bd0

I put in a print self.methods.sort.to_yaml and, sure enough, when I do
this through the browser this is what I see:

  • mark_for_destruction
  • marked_for_destruction?
  • metaclass
  • method
  • method_missing
  • methods
  • new_record?
  • nil?
  • object_id

I put the same check in the controller
@entity = Entity.new
print @entity.methods.sort.to_yaml

and it is missing there as well.

No method_exists?, So, where is it going?

However,

On Thu, Apr 9, 2009 at 9:46 AM, James B. [email protected]
wrote:

/home/byrnejb/Software/Development/Projects/proforma.git/lib/hll_attr_set_by_names.rb:16:in

checking method: entity_legal_name

Posted via http://www.ruby-forum.com/.


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

I just did a github search and the only place I found method_exists?
referenced was in mocha. So my guess is that in test mode, mocha is
being loaded and so it’s passing for you. Try using respond_to?
instead of method_exists? I’ve never even heard of method_exists?
until just now.

Pat

Pat M. wrote:

I just did a github search and the only place I found method_exists?
referenced was in mocha. So my guess is that in test mode, mocha is
being loaded and so it’s passing for you. Try using respond_to?
instead of method_exists? I’ve never even heard of method_exists?
until just now.

Pat

Ahh, thanks. That fixed things. Most disconcerting to have ones tests
pass and the application die.

On Thu, Apr 9, 2009 at 1:55 PM, Pat M. [email protected] wrote:

`method_missing’
17 end
checking method: entity_common_name
I am lost… Help?
being loaded and so it’s passing for you. Try using respond_to?
instead of method_exists? I’ve never even heard of method_exists?
until just now.

Yes - Rails now requires ‘mocha’ in ActiveSupport::TestCase if you
have it on your system. I’ve filed a ticket about this here:
https://rails.lighthouseapp.com/projects/8994/tickets/2240

Cheers,
David

James B. wrote:

  • new_record?

No method_exists?, So, where is it going?

Could be completely off track, Pats mention of Mocha reminded me that
Rails 2.3 tests have lots of ‘require mocha’ dotted around the place:

David raised a ticket on this:

https://rails.lighthouseapp.com/projects/8994/tickets/2240-let-users-decide-what-mock-framework-to-use

Could this be causing some conflict?


Joseph W.

On Thu, Apr 9, 2009 at 2:48 PM, Joseph W. [email protected] wrote:

in development:

  • metaclass
    print @entity.methods.sort.to_yaml
    2.3 tests have lots of ‘require mocha’ dotted around the place:
    It’s not just in Rails’ own tests. It’s actually in
    ActiveSupport::TestCase, which means that if you have mocha installed,
    it’s getting loaded whether you use it or not.

Generally speaking, this should really not be a problem. But there are
those odd cases where a conflict may arise because both rspec-mocks
and mocha add methods to object to support partial mocking/stubbing on
any object. It happens that they use different method names. But, for
example, if we wanted to alias :should_receive with :expects in RSpec
to give it more of mocha’s flavor, we’d be definitely be risking some
unpleasant behaviour.

Cheers,
David