Reputation: 4895
I'm writing a tests for my app with listed gems. I couldn't find how to set Capybara to work with backbone (ajax in all)
example test:
require 'spec_helper' describe "Main" do describe "GET /" do
it "displays articles" do
Article.create!(title:'title',body:'<p>body text</p>')
visit '/'
page.should have_content('body text')
end
end
end
and output of the test:
Failures:
1) Main GET / displays articles
Failure/Error: page.should have_content('body text')
expected there to be text "body text" in "Loading..."
# ./spec/features/main_spec.rb:8:in `block (3 levels) in <top (required)>'
"Loading..." is the pre ajax text in my view template...
The point is that I don't want to use Jasmine at the moment for this app
Upvotes: 0
Views: 1418
Reputation: 15736
It looks like you are running Capybara with the default Rack::Test driver, which means no JavaScript. Rack::Test loads your app in process and fakes a browser DOM behind the Capybara API.
You need to use a driver that runs your tests in a real Web browser. There are a few different options: a Selenium driver comes with Capybara and runs your tests in a real browser (normally Firefox), others are implemented in separate gems, such as Poltergeist which uses PhantomJS and the headless WebKit browser.
There are instructions on the Capybara readme about setting up the right driver. You can switch a group of tests to use a JavaScript supporting driver by adding the js
option to a describe block, e.g.:
describe "Main with JavaScript", :js => true do
# ...
end
Upvotes: 3