Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8004319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:52:58+00:00 2026-06-04T16:52:58+00:00

I’m learning Rspec + Cucumber with The RSpec Book . I’m just at the

  • 0

I’m learning Rspec + Cucumber with The RSpec Book. I’m just at the beginning, while developing a Codebreaker game.

In it, there is a feature “Codebreaker starts game” that represents simply a user typing a command in the shell and getting two responses: “Welcome to Codebreaker!” and “Enter a guess:”. Here it is how the feature looks like:

Feature: code-breaker starts game
   As a code-breaker
   I want to start a game
   So that I can break the code

   Scenario: start game
      Given I am not yet playing
      When I start a new game
      Then I should see "Welcome to Codebreaker!"
      And I should see "Enter a guess:"

As the output is used by the cucumber script, the book is creating a mock object output which is expecting to receive the puts message with Welcome to Codebreaker! and Enter a guess: argument. Here it is how it looks in the step definitions:

#the mock object
class Output
   def messages
      @messages ||= []
   end

   def puts(message)
      messages << message
   end
end

def output
   @output ||= Output.new
end

Given /^I am not yet playing$/ do
end

When /^I start a new game$/ do
   game = Codebreaker::Game.new(output)
   game.start
end

Then /^I should see "([^"]*)"$/ do |message|
   output.messages.should include(message)
end

Ok, up till now no problem.

Doing this exercise, I remembered to had read before that rspeck doubles framework could be used inside cucumber, so I thought I could clean it a little bit.

First, I have included rspeck doubles framework in support/env.rb:

require 'cucumber/rspec/doubles'

And then I have changed the step definitions:

Given /^I am not yet playing$/ do
end

When /^I start a new game$/ do
   @output = double('output').as_null_object #the mock object
   game = Codebreaker::Game.new(@output)
   game.start
end

Then /^I should see "([^"]*)"$/ do |message|
   @output.should_receive(:puts).with(message)
end

The strange think is that now, when I execute the feature with cucumber, in the summary I get all 4 steps passing but not the whole scenario. How is it possible? What is it happening? Here it is the output I get from the command line:

Feature: code-breaker starts game
   As a code-breaker
   I want to start a game
   So that I can break the code

  Scenario: start game                          # features/codebreaker_starts_game.feature:6
    Given I am not yet playing                  # features/step_definitions/codebreaker_steps.rb:1
    When I start a new game                     # features/step_definitions/codebreaker_steps.rb:4
    Then I should see "Welcome to Codebreaker!" # features/step_definitions/codebreaker_steps.rb:10
    And I should see "Enter a guess:"           # features/step_definitions/codebreaker_steps.rb:10
      (Double "output").puts("Welcome to Codebreaker!")
          expected: 1 time
          received: 0 times (RSpec::Mocks::MockExpectationError)
      /home/a_user/www/codebreaker/features/step_definitions/codebreaker_steps.rb:11:in `block in <top (required)>'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/error_generator.rb:80:in `__raise'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/error_generator.rb:39:in `raise_expectation_error'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/message_expectation.rb:251:in `generate_error'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/message_expectation.rb:207:in `verify_messages_received'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/method_double.rb:117:in `block in verify'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/method_double.rb:117:in `each'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/method_double.rb:117:in `verify'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/proxy.rb:88:in `block in verify'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/proxy.rb:88:in `each'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/proxy.rb:88:in `verify'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/methods.rb:116:in `rspec_verify'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/space.rb:11:in `block in verify_all'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/space.rb:10:in `each'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks/space.rb:10:in `verify_all'
      /var/lib/gems/1.9.1/gems/rspec-mocks-2.10.1/lib/rspec/mocks.rb:19:in `verify'
      /var/lib/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/rspec/doubles.rb:12:in `After'

Failing Scenarios:
cucumber features/codebreaker_starts_game.feature:6 # Scenario: start game

1 scenario (1 failed)
4 steps (4 passed)
0m0.009s
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:53:00+00:00Added an answer on June 4, 2026 at 4:53 pm

    When you set an expectation like should_receive, you’re specifying that a some point in the future the specified method should be called – anything that has happened previously is ignored (or else it would be should have_received or something like that in the past tense).

    In your code you’re setting up the expectation in your Then step but the method gets called in your When step (i.e. before), so at that point no expectation has been setup. Your double is setup to allow any method to be called, so you get no errors, but when spec checks at the end whether all expectations have been satisfied it will say no and raise an exception

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.