On Mon, Mar 17, 2008 at 9:59 AM, Bart Zonneveld <[EMAIL PROTECTED]> wrote:
>
> On 17-mrt-2008, at 14:51, Zach Dennis wrote:
>
> > I have been putting helper methods inside of my own modules and then
> > including them in RSpec::Story::World, which included in the context
> > that stories are defined and run in (David, feel free to correct me if
> > this is not 100% accurate).
>
> >
> Hmm, maybe I should clarify some more..
>
> Imagine the following, untested, proof-of-idea code:
>
> steps_for(:adding_posts) do
> def valid_post
> { :title => 'My First Post' }
> end
> end
>
> steps_for(:common) do
> Given "a valid post" do
> post "/posts/create", post => valid_post
> end
> end
>
> valid_post is not defined for steps_for(:common).
I'm sorry my last email should have said Spec::Story::World not
RSpec::Story::World. And your steps are executed in the context of
Spec::Story::World, so it doesn't matter if the method is defined
inside of your steps for.
I understand what you want to do, but you can write better helpers
which don't have this problem. For example I use the form_test_helper
to submit forms in Story's, so I don't have to call "post" directly. I
have a "submit_event_form" which submits a valid form by default.
ie:
def submit_event_form
submit_form "event-form" do |form|
form.event.name = "Foo"
end
end
Then in my step matcher I have something like:
When "they submit the event form with invalid information" do
submit_event_form do |form|
form.event.name = ""
end
end
If I have to reuse that in more then one place I pull it out into a
submit_event_form_with_invalid_information method.
--
Zach Dennis
http://www.continuousthinking.com
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users