James Hughes
2007-Oct-12 19:19 UTC
[rspec-users] Strange mock_model behaviour with ActiveResource model
Hi, I have two models in an app that inherit from ActiveResource::Base. The scaffold controller tests for one of the models works fine, but the other one dies when calling mock_model in the "handling GET /fa_codes" spec: Specifically, the call to mock model here: before do @fa_code = mock_model(FaCode) FaCode.stub!(:find).and_return([@fa_code]) end generates this failure: NameError in ''FaCodesController handling GET /fa_codes should assign the found fa_codes for the view'' uninitialized constant Spec::Rails::Initializer (eval):11:in `class'' /home/jhughes/dev/rj/gump_rewrite/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/rails_example.rb:85:in `add_stubs'' /home/jhughes/dev/rj/gump_rewrite/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/rails_example.rb:73:in `mock_model'' ./spec/controllers/fa_codes_controller_spec.rb:64: This is with edge rails, trunk rspec and rspec_on_rails. I might have pegged this as some Ares wierdness, but there are two models with the same setup, and only one dies like this. Any ideas? James
Bryan Ray
2007-Oct-13 00:01 UTC
[rspec-users] Strange mock_model behaviour with ActiveResource model
Can you post your entire: it "should assign the found fa_codes for the view" block? as well as your fa_code controller? perhaps pastie it and link. That appears to be the spec failing. James Hughes wrote:> Hi, > > I have two models in an app that inherit from ActiveResource::Base. > The scaffold controller tests for one of the models works fine, but > the other one dies when calling mock_model in the "handling GET > /fa_codes" spec: > > Specifically, the call to mock model here: > > before do > @fa_code = mock_model(FaCode) > FaCode.stub!(:find).and_return([@fa_code]) > end > > generates this failure: > > NameError in ''FaCodesController handling GET /fa_codes should assign > the found fa_codes for the view'' > uninitialized constant Spec::Rails::Initializer > (eval):11:in `class'' > /home/jhughes/dev/rj/gump_rewrite/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/rails_example.rb:85:in > `add_stubs'' > /home/jhughes/dev/rj/gump_rewrite/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/rails_example.rb:73:in > `mock_model'' > ./spec/controllers/fa_codes_controller_spec.rb:64: > > This is with edge rails, trunk rspec and rspec_on_rails. I might have > pegged this as some Ares wierdness, but there are two models with the > same setup, and only one dies like this. > > Any ideas? > > James > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > >
James Hughes
2007-Oct-17 19:48 UTC
[rspec-users] Strange mock_model behaviour with ActiveResource model
On 10/12/07, Bryan Ray <bryansray at gmail.com> wrote:> Can you post your entire: > > it "should assign the found fa_codes for the view" block? as well as > your fa_code controller? perhaps pastie it and link. > > That appears to be the spec failing.Hi Brian, It''s actually all of the it blocks inside the "describe FaCodesController, "handling GET /fa_codes" do" block -- and, if they weren''t commented out right now, all of these describe blocks all fail in the same way: describe FaCodesController, "handling GET /fa_codes.xml" do describe FaCodesController, "handling GET /fa_codes/1" do describe FaCodesController, "handling GET /fa_codes/1.xml" do Here''s the model, controller_spec and controller: http://pastie.caboo.se/108209 FYI, I tried changing the base class of the model to ActiveRecord::Base and got the same error. jh> > James Hughes wrote: > > Hi, > > > > I have two models in an app that inherit from ActiveResource::Base. > > The scaffold controller tests for one of the models works fine, but > > the other one dies when calling mock_model in the "handling GET > > /fa_codes" spec: > > > > Specifically, the call to mock model here: > > > > before do > > @fa_code = mock_model(FaCode) > > FaCode.stub!(:find).and_return([@fa_code]) > > end > > > > generates this failure: > > > > NameError in ''FaCodesController handling GET /fa_codes should assign > > the found fa_codes for the view'' > > uninitialized constant Spec::Rails::Initializer > > (eval):11:in `class'' > > /home/jhughes/dev/rj/gump_rewrite/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/rails_example.rb:85:in > > `add_stubs'' > > /home/jhughes/dev/rj/gump_rewrite/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/rails_example.rb:73:in > > `mock_model'' > > ./spec/controllers/fa_codes_controller_spec.rb:64: > > > > This is with edge rails, trunk rspec and rspec_on_rails. I might have > > pegged this as some Ares wierdness, but there are two models with the > > same setup, and only one dies like this. > > > > Any ideas? > > > > James
James Hughes
2007-Oct-18 21:39 UTC
[rspec-users] Strange mock_model behaviour with ActiveResource model
Never mind. User error. jh On 10/17/07, James Hughes <hughes.james at gmail.com> wrote:> On 10/12/07, Bryan Ray <bryansray at gmail.com> wrote: > > Can you post your entire: > > > > it "should assign the found fa_codes for the view" block? as well as > > your fa_code controller? perhaps pastie it and link. > > > > That appears to be the spec failing. > > Hi Brian, > > It''s actually all of the it blocks inside the "describe > FaCodesController, "handling GET /fa_codes" do" block -- and, if they > weren''t commented out right now, all of these describe blocks all fail > in the same way: > > describe FaCodesController, "handling GET /fa_codes.xml" do > describe FaCodesController, "handling GET /fa_codes/1" do > describe FaCodesController, "handling GET /fa_codes/1.xml" do > > Here''s the model, controller_spec and controller: > > http://pastie.caboo.se/108209 > > FYI, I tried changing the base class of the model to > ActiveRecord::Base and got the same error. > > jh > > > > > James Hughes wrote: > > > Hi, > > > > > > I have two models in an app that inherit from ActiveResource::Base. > > > The scaffold controller tests for one of the models works fine, but > > > the other one dies when calling mock_model in the "handling GET > > > /fa_codes" spec: > > > > > > Specifically, the call to mock model here: > > > > > > before do > > > @fa_code = mock_model(FaCode) > > > FaCode.stub!(:find).and_return([@fa_code]) > > > end > > > > > > generates this failure: > > > > > > NameError in ''FaCodesController handling GET /fa_codes should assign > > > the found fa_codes for the view'' > > > uninitialized constant Spec::Rails::Initializer > > > (eval):11:in `class'' > > > /home/jhughes/dev/rj/gump_rewrite/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/rails_example.rb:85:in > > > `add_stubs'' > > > /home/jhughes/dev/rj/gump_rewrite/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/rails_example.rb:73:in > > > `mock_model'' > > > ./spec/controllers/fa_codes_controller_spec.rb:64: > > > > > > This is with edge rails, trunk rspec and rspec_on_rails. I might have > > > pegged this as some Ares wierdness, but there are two models with the > > > same setup, and only one dies like this. > > > > > > Any ideas? > > > > > > James >