Tom Meier
2009-Mar-18 05:00 UTC
[rspec-users] mock_model with Rspec/Rspec-rails 1.2 and Rails 2.3
Hi, Not sure if anyone has faced this problem yet and managed to resolve it... I understand Rspec ''decoupled'' the mock frameworks, however it works fine with Rails 2.2 but fails in 2.3... Can anyone give me any pointers as to what changes are required in spec_helper.rb to ensure mock_model methods are available? Within console I can mock an object with the following: require ''spec'' require ''spec/mocks'' require ''spec/mocks/mock.rb'' require ''spec/rails/mocks.rb'' include Spec include Spec::Mocks include Spec::Mocks::Methods include Spec::Mocks::ExampleMethods include Spec::Rails::Mocks mock_model(User) => #<User:0x1c04c10 @name="User_1001"> However, within spec_helper.rb require "erb" ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/ environment") require ''spec/autorun'' require ''spec/rails'' require ''spec/mocks'' require ''spec/mocks/mock.rb'' require ''spec/rails/mocks.rb'' Spec::Runner.configure do |config| config.include Spec::Mocks config.include Spec::Mocks::Methods config.include Spec::Mocks::ExampleMethods config.include Spec::Rails::Mocks end --- With the above settings when our specs run (while on rails 2.3 and rspec 1.2), the following error occurs : undefined method `mock_model='' for #<User:0x2d5887c> Any pointers in the right direction would be much appreciated... Best regards, Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090318/272afa21/attachment.html>
David Chelimsky
2009-Mar-18 06:37 UTC
[rspec-users] mock_model with Rspec/Rspec-rails 1.2 and Rails 2.3
2009/3/18 Tom Meier <tom at zudio.com.au>:> Hi, > Not sure if anyone has faced this problem yet and managed to resolve it... I > understand Rspec ''decoupled'' the mock frameworks, however it works fine with > Rails 2.2 but fails in 2.3...Why do you put decoupled in quotes? Are you mocking decoupling of mocking?> Can anyone give me any pointers as to what changes are required in > spec_helper.rb to ensure mock_model methods are available? > > Within console I can mock an object with the following: > require ''spec'' > require ''spec/mocks'' > require ''spec/mocks/mock.rb'' > require ''spec/rails/mocks.rb'' > > include Spec > include Spec::Mocks > include Spec::Mocks::Methods > include Spec::Mocks::ExampleMethods > include Spec::Rails::Mocks > mock_model(User) > => #<User:0x1c04c10 @name="User_1001"> > > However, within spec_helper.rb > > require "erb" > ENV["RAILS_ENV"] = "test" > require File.expand_path(File.dirname(__FILE__) + "/../config/environment") > require ''spec/autorun'' > require ''spec/rails'' > require ''spec/mocks'' > require ''spec/mocks/mock.rb'' > require ''spec/rails/mocks.rb'' > Spec::Runner.configure do |config| > ?? config.include Spec::Mocks > ?? config.include Spec::Mocks::Methods > ?? config.include Spec::Mocks::ExampleMethods > ?? config.include Spec::Rails::Mocks > > end > > > > --- > With the above settings when our specs run (while on rails 2.3 and rspec > 1.2), the following error occurs : > undefined method `mock_model='' for #<User:0x2d5887c>The error says "mock_model=", which indicates that you''re trying to set it somewhere in your code. Please show us the spec that is failing with a reference to the line that is raising that error. Thx> > > Any pointers in the right direction would be much appreciated... > > > > > Best regards, > Tom > > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Pat Maddox
2009-Mar-18 16:54 UTC
[rspec-users] mock_model with Rspec/Rspec-rails 1.2 and Rails 2.3
On Mar 17, 2009, at 11:37 PM, David Chelimsky wrote:> 2009/3/18 Tom Meier <tom at zudio.com.au>: >> >> With the above settings when our specs run (while on rails 2.3 and >> rspec >> 1.2), the following error occurs : >> undefined method `mock_model='' for #<User:0x2d5887c> > > The error says "mock_model=", which indicates that you''re trying to > set it somewhere in your code. Please show us the spec that is failing > with a reference to the line that is raising that error.I think this would require him to do self.mock_model = blah or send("mock_model=", blah) which seems really, really weird. Oh well. Some code ought to clear it up. Pat