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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:20:18+00:00 2026-06-01T05:20:18+00:00

I’m clicking show and destroy links with Capybara that should be in the first

  • 0

I’m clicking show and destroy links with Capybara that should be in the first table row in an employees table. The table should sort so that the most recently modified employee is on the top, based on the updated_at timestamp.

Before the example a valid employee must be created that passes authentication. Then at the beginning of the example an employee must be created to test with. This is the employee that should always be at the top of the table because it’s supposed to have been modified most recently. Sometimes it is and sometimes it isn’t. Adding a sleep call fixes this, and I’m wondering if that’s valid or if I’ve got it wrong. I thought adding a sleep call in a test was a Bad Thing. I also thought if the authentication employee is created before the example then even if my spec is running really fast then it should still have an earlier updated_at timestamp.

The authentication macro:

module AuthenticationMacros
  def login_confirmed_employee
    # create a valid employee for access
    Factory :devise_confirmed_employee,
      :username => 'confirmed.employee',
      :password => 'password',
      :password_confirmation =>'password'

    # sign in with valid credentials
    visit '/employees/sign_in'
    fill_in 'Username', :with => 'confirmed.employee'
    fill_in 'Password', :with => 'password'
    click_on 'Sign In'
  end
end

The request spec in question:

require 'spec_helper'
include AuthenticationMacros

describe "Employees" do

  before do
    login_confirmed_employee
  end

  # shows employees
  it "shows employees" do
    sleep 1.seconds
    Factory :employee_with_all_attributes,
      :username => 'valid.employee',
      :email => 'valid.employee@example.com',

    visit '/employees'
    within 'tbody tr:first-child td:last-child' do; click_on 'Show', end
    page.should have_content 'valid.employee'
    page.should have_content 'valid.employee@example.com'
  end


  # destroys employees
  it "destroys employees" do
    sleep 1.seconds
    Factory(:employee)
    visit '/employees'
    within 'tbody tr:first-child td:last-child' do; click_on 'Delete', end
    page.should have_content 'Employee was successfully deleted.'
  end
end 

And for good measure here’s my spec_helper:

require 'spork'

Spork.prefork do

  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  ActiveSupport::Dependencies.clear
  require 'email_spec'
  RSpec.configure do |config|
    config.include EmailSpec::Helpers
    config.include EmailSpec::Matchers
  end
end

Spork.each_run do
  require 'rspec/rails'
  require 'factory_girl_rails'
  require 'capybara/rspec'
  require 'capybara/rails'
  require 'shoulda'

  RSpec.configure do |config|

    config.mock_with :rspec
    config.use_transactional_fixtures = false

    config.before(:suite) do
      DatabaseCleaner.strategy = :truncation
    end

    config.before(:each) do
      DatabaseCleaner.start
    end

    config.after(:each) do
      DatabaseCleaner.clean
    end
  end
end

Sometimes I end up on the show page or destroying the authentication-required employee instead of the example employee.It never happens though if I add the 1 second sleep call.

  • 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-01T05:20:19+00:00Added an answer on June 1, 2026 at 5:20 am

    Nope, it fact it’s a very bad solution because it increases tests execution time.
    You could mock Time.now method call using one of the following solutions:

    • https://github.com/bebanjo/delorean
    • https://github.com/jtrupiano/timecop
    • 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 ’ 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've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
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
We're building an app, our first using Rails 3, and we're having to build
I want to show the soap response to UIWebview.. my soap response is, <p><img
I know there's a lot of other questions out there that deal with this

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.