Hi Cynthia

class_spy doesn’t override the constant automatically, it requires you to add 
.as_stubbed_const so it will override the constant when you call it from your 
controller. class_spy is essentially class_double.as_null_object, see the docs 
here: 
https://relishapp.com/rspec/rspec-mocks/v/3-0/docs/verifying-doubles/using-a-class-double

Regards
Jon Rowe
---------------------------
jonrowe.co.uk


On Monday, 8 September 2014 at 9:04, Cynthia Kiser wrote:

> I am trying to test that a particular Rails controller action deletes all 
> items and then recreates them from an RSS feed. The new class_spy method 
> seemed just perfect for what I was trying to do but I can't get it to work. 
> What am I misunderstanding from the docs?
>  
> /app/controllers/news_configuration_controller.rb
>  
> class NewsConfigurationController < ApplicationController
>   # GET /news_configuration/refresh_from_www
>   def refresh_from_www
>     NewsRelease.delete_all
>     redirect_to news_configuration_path
>   end
> end
>  
> /spec/controllers/news_configuration_controller_spec.rb
>  
> RSpec.describe NewsConfigurationController, :type => :controller do
>  
>   describe "GET 'refresh_from_www'" do
>     it "refreshes news releases" do
>       news_release_class = class_spy("NewsRelease")
>       get :refresh_from_www, { }, valid_session
>       expect(news_release_class).to have_received(:delete_all)
>     end
>  
>  
>  
> --  
> You received this message because you are subscribed to the Google Groups 
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> (mailto:[email protected]).
> To post to this group, send email to [email protected] 
> (mailto:[email protected]).
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rspec/4447f117-4857-46eb-9c49-44fab1ca5bfb%40googlegroups.com
>  
> (https://groups.google.com/d/msgid/rspec/4447f117-4857-46eb-9c49-44fab1ca5bfb%40googlegroups.com?utm_medium=email&utm_source=footer).
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/034F94CB60944FD1AFD23E37B0DAF4AC%40jonrowe.co.uk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to