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 7937787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:36:47+00:00 2026-06-03T22:36:47+00:00

Please note: I am new to TDD & cucumber, so the answer may be

  • 0

Please note: I am new to TDD & cucumber, so the answer may be very easy.

I am creating a basic image editor for a test (the image is just a sequence of letters).
I have written a Cucumber story:

Scenario Outline: edit commands
    Given I start the editor
    And a 3 x 3 image is created
    When I type the command <command>
    Then the image should look like <image> 

The step

Scenarios: colour single pixel
    | command   | image     |
    | L 1 2 C   | OOOCOOOOO |

always fails, returning

  expected: "OOOCOOOOO"
       got: " OOOOOOOO" (using ==) (RSpec::Expectations::ExpectationNotMetError)

This is the step code:

When /^I type the command (.*)$/ do |command|
  @editor.exec_cmd(command).should be
end

The function exec_cmd in the program recognizes the command and launches the appropriate action. In this case it will launch the following

def colorize_pixel(x, y, color)
  if !@image.nil?
    x = x.to_i 
    y = y.to_i
    pos = (y - 1) * @image[:columns] + x
    @image[:content].insert(pos, color).slice!(pos - 1)
  else
    @messenger.puts "There's no image. Create one first!"
  end
end

However, this always fails unless I hardcode the values of the two local variables (pos and color) in the function in the program itself.

Why? It doesn’s seem I’m doing anything wrong in the program itself: the function does what it’s supposed to do and those two variables are only useful locally. So I’d think this is a problem with my use of cucumber. How do I properly test this?

—edit—

def exec_cmd(cmd = nil)
  if !cmd.nil? 
    case cmd.split.first
      when "I" then create_image(cmd[1], cmd[2])
      when "S" then show_image
      when "C" then clear_table
      when "L" then colorize_pixel(cmd[1], cmd[2], cmd[3])
    else
      @messenger.puts "Incorrect command. " + "Commands available: I C L V H F S X."
    end
  else 
    @messenger.puts "Please enter a command."
  end
end
  • 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-03T22:36:49+00:00Added an answer on June 3, 2026 at 10:36 pm

    It’s not a cucumber issue.

    The problem was that, in exec_cmd, split was called only in the “case” clause, not in the “when”s. This meant that, since the command’s format was “a 1 2 b”, cmd[1] in the “when” would call the second character of the string, a space, not the second value of the array, and the other functions would convert that to_i, returning 0.

    I changed exec_cmd like this:

    def exec_cmd(cmd = nil)
      if !cmd.nil?
        cmd = cmd.split
        case cmd.first
        when "I" then create_image(cmd[1], cmd[2])
        [...]
    end
    

    which fixed the issue.

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

Sidebar

Related Questions

Please note that I am very new to .NET and ASP.NET. I have a
Before reading, please note that I am very new to both PHP and MYSQL.
PLEASE NOTE: I've answered my own question with a link to an answer to
Please note I'm totally new to ASP.NET.. How can I have the username, password
I need to set image source dynamically, please note my image is in somewhere
Please note: I am new to CS. Brand new. I want my button div
EDIT: Please note that while I received an answer, I don't understand what's wrong
I'm having a problem trying to use ZeroMQ in my new application. Please note:
please note to this: public class test extended Jframe implement actionlistener{ test() { Jpanel
Please note i am new to LINQ to XML. I am now trying to

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.