Peter Fitzgibbons
2006-Sep-18 16:53 UTC
[mocha-developer] Mocha + Selenium-on-rails loading problem ?
Hello All, I need to stub two class methods before a selenium call. The .rsel is : require ''mocha'' SalesConfigWork.stubs(:load_work_data) SalesConfigWork.stubs(:delete_work_data) setup :fixtures => :sales_config_works open "/" The Selenium test runner result is : undefined method `stubs'' for SalesConfigWork:Class Extracted source (around line *#0*): 1: require ''mocha'' 2: 3: SalesConfigWork.stubs(:load_work_data) RAILS_ROOT: ./script/../config/.. I understand this might be a stretch to ask; what do you think is happening here ? Thanks for your time! -- ------------------------------ Apple MacBook. Black. It''s the new White! ------------------------------ Peter Fitzgibbons -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20060918/a038d678/attachment.html
James Mead
2006-Sep-18 17:17 UTC
[mocha-developer] Mocha + Selenium-on-rails loading problem ?
On 18/09/06, Peter Fitzgibbons <peter.fitzgibbons at gmail.com> wrote:> > I''m waiting on my subscription to the mailing list. Until then, I wanted > to send you this. >I just approved it - somehow it got sucked into my spam filter - sorry for the delay. I need to stub two class methods before a selenium call.> > The .rsel is : > > require ''mocha'' > > SalesConfigWork.stubs(:load_work_data) > SalesConfigWork.stubs(:delete_work_data) > > setup :fixtures => :sales_config_works > open "/" > > The Selenium test runner result is : > > undefined method `stubs'' for SalesConfigWork:Class > > Extracted source (around line *#0*): > > 1: require ''mocha'' > 2: > 3: SalesConfigWork.stubs(:load_work_data) > > RAILS_ROOT: ./script/../config/.. > > I understand this might be a stretch to ask; what do you think is > happening here ? > > Thanks for your time! >You need to include the Stubba part of Mocha if you want to stub classes and non-mock objects... require ''mocha'' require ''stubba'' You need to make sure these are required after the Rails Test::Unit stuff which normally gets loaded in test_helper.rb when it requires test_help.rb. I haven''t tried Mocha with Selenium-on-Rails, so let me know how it goes. Hope that helps, -- James. http://blog.floehopper.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20060918/adb0f181/attachment-0001.html
James Mead
2006-Sep-18 17:39 UTC
[mocha-developer] Mocha + Selenium-on-rails loading problem ?
On 18/09/06, Peter Fitzgibbons <peter.fitzgibbons at gmail.com> wrote:> > HI James, > > I put the requires in test_helper.rb for simplicity. > > Now on the .rsel (without the require call) I get : > > c:/ruby/lib/ruby/gems/1.8/gems/mocha-0.3.2/lib/stubba/object.rb:47:in `stubs'': You have a nil object when you didn''t expect it! > > The error occured while evaluating nil.stub > > Extracted source (around line *#0*): > > 1: > 2: SalesConfigWork.stubs(:load_work_data) > 3: SalesConfigWork.stubs(:delete_work_data) > > > If there''s a puts or a breakpoint inspect you''d like to see, tell me. >I''m pretty sure this will be because of interference between setup methods. I''m working on a way of making Mocha play better with other test frameworks, but to be honest its a general problem of the way Test::Unit itself works. I''m guessing Selenium-on-Rails defines setup method & teardown methods for TestCase. You could try adding the following code (assuming mocha and stubba have already been required)... def setup setup_stubs # existing code here end def teardown # existing code here teardown_mocks teardown_stubs end You should be warned that I''m guessing a bit and haven''t tested this at all! -- James. http://blog.floehopper.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20060918/a893a47c/attachment.html
Reasonably Related Threads
- Using Selenium with a mock-method on associated Model ???
- Problem with RSpec and Mocha/Stubba
- Mocha, Stubba and RSpec
- Fwd: [ mocha-Bugs-5892 ] Using a setup method in test_case_class destroys subsequent test cases
- [PATCH] libxl: reimplement buffer for bootloading and drop data if buffer is full