Tero Tilus
2009-May-19 06:04 UTC
[rspec-users] [RSpec, Rails] POST create action spec and before_filter
2009-05-18 21:40, Florent Florent:> I have this controller: http://pastie.org/482270 > I wrote this spec: http://pastie.org/482273There are a few spots which draw my attention. At spec line 4 you create a mock Page with #save that always fails (succesfull save returns true). Is that intentional? At line 9 you .and_return a value from a variable you don''t set anywhere. Moreover the "should set @context" is imo a spec smell (even though it''s in description string), because it refers to internal state of a PagesController instance, which you should not be interested in, but the external behavior.> The spec "should set @context" works fine. But when running the > spec "should build a new message" I got this error: > > <Page(id: integer, title: string, content: text, created_at: > datetime, updated_at: datetime) (class)> expected :new with > ({"title"=>"Introduction", "content"=>"page d''introduction"}) once, > but received it 0 timeCould that have something to do with the fact that you end up stubbing Page.new one or two times before setting the expectation on it at line 14? It shouldn''t, but you never know.> I can not find why Page model does not receive new call, and playing > around I can have the spec running successfully when I remove > :create from the before_filter line!Could your filter be failing and the failure not showin up somehow? Does "should set @context" _really_ succeed? Comment the other example one out and then try again. Generally you shouldn''t expect your examples (or specs) to run in any particular order. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
Tero Tilus
2009-May-19 19:11 UTC
[rspec-users] [RSpec, Rails] POST create action spec and before_filter
2009-05-19 10:22, Florent Florent:> BTW how can I spec that my @context is correctly set by my filter?How can you tell from _outside_ if the context is properly set or not? What does your controller use the context for? And what happens if the controller does or doesn''t know about the context? -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/