Hi all,
I am using story runner with webrat, but I am not sure how to
incorporate stub_model into my tests.
The webrat steps only care about the user interface and have nothing
to say about interaction with the database.
Following Ben M., I have a line in my story like:
“When clicks the Create button”
And a step like:
When “clicks the $button button” do |button|
clicks_button button
end
Would it be sensible to extend it as follows:
“And clicks the Create button to create a new thing”
With step:
When “clicks the $button button to create a new $resource” do |button,
resource|
klass = resource.classify.constantize
stub_model(klass)
clicks_button button
end
Or is there a better way of making sure that all required models are
stubbed?
many thanks,
danny
On Jun 24, 2008, at 10:39 AM, Danny Sofer wrote:
Hi all,
I am using story runner with webrat, but I am not sure how to
incorporate stub_model into my tests.
I’d recommend avoiding this. Stories are for integration testing.
Examples are for isolation - that’s where you want to be stubbing out
models.
clicks_button button
klass = resource.classify.constantize
stub_model(klass)
clicks_button button
end
The stub_model method is not implicitly available in stories, but they
are in a module that you can include in RailsStory if you really want
to:
RailsStory.send :include, Spec::Rails::Mocks
Or is there a better way of making sure that all required models are
stubbed?
If your concern is global DB access and you really think you don’t
need the DB for your stories, I’d recommend something like UnitRecord
or NullDB instead. They can take care of things globally for you,
reading schema.rb to get and cache the columns rather than hitting the
db.
HTH,
David