测试轨道使用RSpec&AMP +骨干申请;水豚 [英] testing rails+backbone application with rspec & capybara

查看:132
本文介绍了测试轨道使用RSpec&AMP +骨干申请;水豚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个测试我与上市宝石应用程序。我找不到如何设置水豚与骨干网(阿贾克斯全部)的结果工作
例如测试:

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

和测试的输出:

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)>'

正在加载...在我看来模板中的pre阿贾克斯文字...

"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

推荐答案

它看起来像您正在使用默认的机架::测试驱动程序,这意味着没有JavaScript的运行水豚。机架::测试加载过程中您的应用程序和假货的水豚API后面的浏览器的DOM。

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.

您需要使用运行在一个真正的Web浏览器测试的驱动程序。有几个不同的选择:一个司机硒自带的水豚并运行你在一个真正的浏览器(通常Firefox)的测试,其他人都在不同的宝石,如的骚灵,它使用PhantomJS和无头WebKit浏览器

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.

有对水豚说明自述有关设置正确的驱动程序。您可以切换一组测试中加入 JS 选项为一个描述块,例如使用JavaScript支持驱动程序:

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

这篇关于测试轨道使用RSpec&AMP +骨干申请;水豚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆