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.
def my_account @my_account ||= Account.create!(:number => "test", :balance => 0) end
Before do DatabaseCleaner.clean end
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 DatabaseCleaner.clean Account.create!(:number => "test", :balance => 0) end
def my_account @my_account ||= Account.find_by(:number => 'test') end
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?