Forum: RSpec [cucumber] Tests pass, application does not.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-04-09 18:46
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:in
`attr_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?
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-04-09 19:04
James Byrne 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,
39100495c9937c39b2e0c704444e1b4a?d=identicon&s=25 Pat Maddox (Guest)
on 2009-04-09 19:26
(Received via mailing list)
On Thu, Apr 9, 2009 at 9:46 AM, James Byrne <lists@ruby-forum.com>
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
> rspec-users@rubyforge.org
> 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
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-04-09 19:44
Pat Maddox 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.
3c28deaff162aeda44f2e0bcdca1dacf?d=identicon&s=25 Joseph Wilk (josephwilk)
on 2009-04-09 19:58
(Received via mailing list)
James Byrne 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/tick...

Could this be causing some conflict?

--
Joseph Wilk
http://blog.josephwilk.net
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-04-09 20:02
(Received via mailing list)
On Thu, Apr 9, 2009 at 1:55 PM, Pat Maddox <pat.maddox@gmail.com> 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
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-04-09 20:15
(Received via mailing list)
On Thu, Apr 9, 2009 at 2:48 PM, Joseph Wilk <joe@josephwilk.net> 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.

http://github.com/rails/rails/blob/660fc93942697b7...

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
This topic is locked and can not be replied to.