small medium large xlarge

07 May 2016, 07:41
Sarah Neuber (2 posts)

Hello, I am a beginner to Ruby and Cucumber and an eager student :)

I came across a “Flickering Scenario” in chapter 10 which I need help to resolve please.

Code setup:

In features/support/world_extensions.rb

def my_account
    @my_account ||= Account.create!(:number => "test", :balance => 0)

In features/support/database.rb

Before do

Run the cucumber example 4-5 times in a row. The example works the first 3 times but by the 4th or 5th time it fails with the following error:

Starting transaction_processor in /home/sarah/Documents/learning-resources/calculator with 'ruby lib/transaction_processor.rb'
transaction processor ready
Server transaction_processor (27119) is up.
Feature: Cash Withdrawal

  Scenario: Successful withdrawal from an account in credit # features/cash_withdrawal.feature:2
    Given my account has been credited with $100            # features/step_definitions/account_steps.rb:1
    When I request $20                                      # features/step_definitions/teller_steps.rb:1
    Then $20 should be dispensed                            # features/step_definitions/cash_slot_steps.rb:1
lib/transaction_processor.rb:10:in `block (2 levels) in <main>': undefined method `strip' for nil:NilClass (NoMethodError)
	from /home/sarah/Documents/learning-resources/calculator/lib/transaction_queue.rb:21:in `read'
	from lib/transaction_processor.rb:7:in `block in <main>'
	from lib/transaction_processor.rb:6:in `loop'
	from lib/transaction_processor.rb:6:in `<main>'
    And the balance of my account should be $80             # features/step_definitions/account_steps.rb:5
      expected: 80
           got: 0

A case of a “flickering Scenario”? I

At first I suspected that the Before hook had a timing issue with the World setup. So I change the code to create the account in the Before hook just after we cleaned the Database. Then in the World setup I simply find the account:

Before do
  Account.create!(:number => "test", :balance => 0)
def my_account
    @my_account ||= Account.find_by(:number => 'test')

However this does not improve things one bit. In fact the cucumber scenario fails the second time it is run with the same error as I mentioned earlier.

What gives? Could someone please point me to the right direction?



08 May 2016, 20:04
Matt Wynne (91 posts)

Hi Sarah,

Which page are you on, exactly? That example evolves quite a bit through the chapter, so it’s helpful to know.

09 May 2016, 15:00
Sarah Neuber (2 posts)

Hi! So glad to have you reply :)

OK so this is on the 10.5 heading on page 185-187 The code is in it’s final version.

The book indicates that the scenario should be passing and it does however not when run 4-5 times back to back as I already explain in my initial comment.

Thanks so much for looking into this!

You must be logged in to comment