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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:57:07+00:00 2026-05-26T08:57:07+00:00

I’m having some problems using Sinatra with Capybara. I want to test a pure

  • 0

I’m having some problems using Sinatra with Capybara.

I want to test a pure javascript application. It’s just a plain index.html that is being served by Sinatra.

require "sinatra"

get "/" do
  File.read("public/index.html")
end

Let’s say for example that I want to test this code.

$("a.link").click(function(){
  $(this).replaceWith("New String");
});

<a href="#link" class="link">Click me!</a>

Then the test would look something like this.

describe "requests", js: true do    
  it "should display a message" do
    visit "/"
    click_link "Click me!"
    page.should have_content("New String")
  end
end

The problem is that nothing happens. According to Ryan Bates screencast Firefox should start and run the test if js: true is added to the describe block.

Here is my spec_helper file.

require "rspec"
require "capybara"
require "capybara/dsl"

Capybara.javascript_driver = :selenium
require_relative "./../server"

Capybara.app               = Sinatra::Application
Capybara.javascript_driver = :selenium
Capybara.default_wait_time = 10

RSpec.configure do |config|
  config.mock_with :rspec
  config.include Capybara
end

Here is the output when running rspec rspec/request_spec.rb.

requests
  should display a message (FAILED - 1)

Failures:

  1) requests should display a message
     Failure/Error: page.should have_content("New String")
       expected #has_content?("New String") to return true, got false
     # ./spec/request_spec.rb:5:in `block (2 levels) in <top (required)>'

Finished in 4.38 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/request_spec.rb:2 # requests should display a message

I created an complete example project on Github that can be found here:
https://github.com/oleander/capybara-js-fails

Anyone knows why it fails?

  • 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-26T08:57:07+00:00Added an answer on May 26, 2026 at 8:57 am

    Here is the original answer from Jonas Nicklas.

    You need to require ‘capybara/rspec’ and set :type => :request.
    See the Capybara README section on “Using Capybara with RSpec”.
    /Jonas

    Here is a working example on Github.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
We're building an app, our first using Rails 3, and we're having to build
I am reading a book about Javascript and jQuery and using one of the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a French site that I want to parse, but am running into

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.