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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:51:27+00:00 2026-06-10T12:51:27+00:00

I’m using Capybara through Cucumber to test a Rails app. The Rails app has

  • 0

I’m using Capybara through Cucumber to test a Rails app.

The Rails app has some seed data in db/seeds.rb, which sets up the authorisation roles and a default user account, and I’ve added a test_seed.rake file to seed the test database after rake db:test:prepare is run, as rake db:seed doesn’t seed the test database.

When I run the Cucumber features using Capybara, this seed data is left alone, and any changes made in testing each feature are rolled back.

However, if I try to test an AJAX-based feature, by putting @javascript in front of the test so Selenium will run it, the seed data is erased once the test is complete. This means subsequent authorisation-based tests fail until rake db:test:prepare is run again, as they are unable to find a role_id when creating user accounts.

Why is Selenium doing this? More to the point, how can I stop it?

(I know I could use Cucumber hooks to load the data before each test. But this data also needs to be loaded before the RSpec-based unit tests. It also needs to be loaded into the development and production databases. So using the built-in seed mechanism seems to be more DRY. In any case, the database shouldn’t be rolled back differently just because Selenium got invoked!)

Edit: I’m using database_cleaner with the :transaction strategy. The docs at https://github.com/jnicklas/capybara mention database_cleaner, but seem to only be talking along the lines of using it with :truncation to make everything else work the same way as Capybara does things when invoking external browsers. I’ve not tried the patch on that page as I don’t fancy “strange failures” — is there a cleaner way? I’m beginning to think removing the tests and just eyeballing the AJAX stuff would be the quickest, easiest way…

  • 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-10T12:51:29+00:00Added an answer on June 10, 2026 at 12:51 pm

    I ended up changing the DatabaseCleaner.strategy to :truncation for both Cucumber and RSpec, and moving to SeedFu to seed the database.

    For Cucumber, add this to env.rb:

    Before do
      SeedFu.quiet = true
      SeedFu.seed
    end
    

    (remember to change the DatabaseCleaner.strategy!)

    For RSpec, add this to spec_helper.rb:

    config.before(:suite) do
      DatabaseCleaner.strategy = :transaction
      DatabaseCleaner.clean_with(:truncation)
    end
    
    config.before(:each) do
      DatabaseCleaner.start
      SeedFu.quiet = true
      SeedFu.seed
    end
    
    config.after(:each) do
      DatabaseCleaner.clean
    end
    

    Sadly, this makes all tests run a little bit slower, as previously the database was only seeded once and then rolled back, as opposed to being seeded each time. Even with only five roles in the seed file, it’s noticeable.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.