On Jul 17, 2008, at 7:40 AM, Jonathan L. wrote:
On Thu, 2008-07-17 at 07:28 -0500, David C. wrote:
I’m wondering why the examples aren’t more specific though. Why is it
OK that the action could be one of two possibilities given a specific
set of givens?
Ok well I lied a little bit
I am using it in a story step, specifically the step is “Then the form
should be shown”. I guess I could split them into “Then the new/edit
form should be shown” but it doesn’t seem a huge issue…
Aha. Now that’s a horse of a different color. I tend to avoid details
like that in story steps. I prefer to expect what’s visible, submit
forms (whatever the action is) and expect to end up in the right place.
Are you familiar with Webrat? It’s a tool that allows you to describe
things at a much higher level and takes care of the low level detail
for you. So rather than expecting specific form elements in the story
steps, you just do things like this:
Given I am registered as David with password Secret
And am and Administrator
When I log in with David/Secret
Then I should see Manage Schedules in a list of Things To Do
The interesting step here is “When I sign in with David/Secret”:
When /I log in with (.)/(.)/ do |login, password|
visits “/login”
fills_in “Login”, :with => login
fills_in “Password”, :with => password
clicks_button “Log In”
end
The fills_in method does two things at once: expects to find an item
with either an id of “Login” or with a related form label that has the
text “Login”. Then it manipulates the DOM, setting the value of that
element to “David” (in this example). Then #clicks_button finds a
button with the text “Log In”, builds a POST from the related DOM
elements and submits the POST.
I use this 100% of the time for Rails stories these days and am
overall very happy with the resulting code.
FWIW,
Cheers,
David