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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:55:31+00:00 2026-05-31T05:55:31+00:00

The following scenario pretty much sums up my problem: Scenario: problems with subprocesses Given

  • 0

The following scenario pretty much sums up my problem:

Scenario: problems with subprocesses
  Given the date is 01/01/2012 10:31
  When I run `ruby -e "puts Time.now"`
  Then the output should contain "10:31"

It boils down to When I run ruby -e "puts Time.now" launching a child process and thus making all of my Timecop.freeze stubs ineffective, since they only work on the main process. I need to somehow ‘inject’ the current context into the command that is run, but I seem to be unable to come up with anything. Am I trying something impossible here?


The step:

require 'timecop'
Given /^the date is (\d+)\/(\d+)\/(\d+) (\d+):(\d+)$/ do |month, day, year, hour, minute|
  Timecop.freeze(Time.local(year.to_i, month.to_i, day.to_i, hour.to_i , minute.to_i, 0))
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-05-31T05:55:32+00:00Added an answer on May 31, 2026 at 5:55 am

    I see 2 options here.

    1. Create a hook in the system under test that you can use to inject the required context, in this example you could add a ‘current time’ parameter to the command line app that you’re testing. Alternatively specify a fixed time in the apps config file, or database, there are many options. This presumes that you own the app that you’re testing and can make such changes. This need only be a very small change, e.g. if the ‘current time’ parameter is specified, then use Timecop to freeze the time at that time.

    2. Find some way to bring the system under test into the Cucumber process. In your example instead of shelling out to ruby -e "puts Time.now", you could instance_eval "puts Time.now". More realistically, you could require the app, and if the command-line runner is simply a thin wrapper around some classes which actually do the work, then you can call those directly. Alternatively, you might be able to populate whatever ARGV parameters are expected, mock out the puts method, and just require the file, which should give you a close experience to running it out of process, but you’d be able to use Timecop effectively.

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

Sidebar

Related Questions

Following scenario. Real time camera feed processing with openCV on ios using dispatch asnyc.
I have a pretty simple scenario. I have the following HTML: <h1>Hello</h1> <input type="button"
I have the following seemingly simple scenario, however I'm still pretty new to NHibernate.
Imagine following scenario: We have a lot of parallel development going on in several
Consider following scenario: I have RESTful URL /articles that returns list of articles user
I often encounter the following scenario where I need to offer many different types
Imagine having the following scenario: You need to create a system where the Back
I have the following scenario I have a main form as MDI parent and
How would the following scenario best be implemented: There is a standardized user interface
Please consider the following scenario: map(T,S*) & GetMap(); //Forward decleration map(T, S*) T2pS =

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.