The `change` matcher requires a block to execute so it can evaluate before / 
after, but the one liner syntax doesn’t support that, so you need to use the 
third form, to improve readability here you could use the named subject, 
`subject(:index) { get :index }` and thus `expect { index }.to change { 
assigns(:assets) }.from(nil)`

Jon Rowe
---------------------------
[email protected]
jonrowe.co.uk


On Wednesday, 11 March 2015 at 13:45, Greg Lappen wrote:

> Hi all, long time-user here, but first time poster... I've been a fan of 
> rspec for about 6 years now.
>  
> Anyway, I'm writing because I'm making some specs and trying to use the 
> one-liner syntax to keep it brief.  It works, except for when I try to use it 
> with the change matcher.  It's a simple controller spec I'm doing:
>  
>     describe "GET #index" do
>       subject { get :index }
>  
>       it { should be_success }
>  
>       # attempt 1
>       it { is_expected.to change{assigns(:assets)}.from(nil) }
>  
>       # attempt 2
>       it { should change{assigns(:assets)}.from(nil) }
>  
>       # attempt 3
>       it "should assign @asset" do
>         expect{subject}.to change {assigns(:assets)}.from(nil)
>       end
>     end
>  
>  
> Both attempt 1 and 2 above fail with the message "expected result to have 
> changed from nil, but was not given a block".  Attempt 3 succeeds.
>  
> Can anyone explain what's going on here?
>  
> Thanks so much!
>  
> Greg
>  
>  
>  
> --  
> 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/3549afe2-70b2-4cd2-8fd1-6f31ad42b13f%40googlegroups.com
>  
> (https://groups.google.com/d/msgid/rspec/3549afe2-70b2-4cd2-8fd1-6f31ad42b13f%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/0E26F0B149EA4717B78923D97F8A49D0%40jonrowe.co.uk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to