On 9/21/07, Andrew WC Brown <
omen.king@...> wrote:
> I'm trying to generate stories based on Dan North's example.
> I'm not sure how to do this.
>
> require File.join(File.dirname(__FILE__), "helper")
>
> Story "Account Holder withdraws cash", %{
> As an Account Holder
> I want to withdraw cash from an ATM
> So that I can get money when the bank is closed
> }, :type => RailsStory do
>
> Scenario "Account has sufficient funds" do
>
> Given "the account balance is $", 100 do |amount|
> @account = Account.new(:balance => 100)
> end
> And "the card is valid" do
> @account.should_not have.error_on(:balance)
> end
> And "the machine contains enough money" do
> @account.sufficient_funds?
> end
> When "the Account Holder requests $", 20 do |amount|
> @account.withdraw(amount)
> end
> Then "the ATM should dispense $", 20 do |amount|
> post "/account/show", :account => {:amount => amount} #show the receipt
> end
> And "the account balance should be $", 80 do
> @account.balance.should be_eql(80)
> end
> And "the card should be returned" do
> post "account/index"
> end
> end
> Scenario "Account has insufficient funds" do; end
> Scenario "Card has been disabled" do; end
> Scenario "The ATM has insufficient funds" do; end
>
> end
> Scenario: Account has sufficient funds
>
> Given the account balance is $ 100
> F
> Scenario: Account has insufficient funds
> .
> Scenario: Card has been disabled
> .
> Scenario: The ATM has insufficient funds
> .
>
>
>
> 4 scenarios: 3 succeeded, 1 failed, 0 pending
>
>
> FAILURES:
> 1) Account Holder withdraws cash (Account has sufficient funds) FAILED
> NameError: uninitialized constant Account
>
> /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:266:in
> `load_missing_constant'
>
>
> When a failure occurs in a story does it always print out a heapstack or is
> my code incorrect?
>
Your code looks correct.
My interpretation of the workflow that derives from this tool is that
you write a high level story like you have here, run it, and let it
tell you what to do next. The stack trace is telling you that you need
an Account class. So now you would drop down to the object level and
write a spec for Account (this is a Rails Story, so you'd write a
model spec). Once you have that passing, you might come back up to the
story level and re-run it, at which point it might tell you that it
doesn't know about the balance() method on your account object; this
would depend on how detailed you got in your model spec.
I'm a total noob with this tool as well, so others on this list might
have different insights; I'd be interested in hearing other
perspectives on how detailed you'd get the first time you drill down
to the object level: would you spec out the object completely as
specified at the high level and then verify that it satisfies the
story, or would you keep ping-ponging back and forth between the two
levels?
James
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users