无法通过railstutorial.org第3章获得rspec测试

时间:2014-09-22 12:26:25

标签: ruby-on-rails rspec capybara

我正在迈克尔·哈特尔(Michael Hartl)做轨道tutorial,我无法在第3章中通过考试。

static_pages.rb文件:

require 'spec_helper'

describe "Static pages" do

  describe "Home page" do

    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      expect(page).to have_content('Sample App')
    end
  end
end

home.html.erb文件:

<h1>Sample App</h1>
<p>
  This is the home page for the
  <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
  sample application.
</p>    

这是测试的结果:

An error occurred in an after hook
  ArgumentError: rack-test requires a rack application, but none was given
  occurred at C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/capybara-2.1.
0/lib/capybara/rack_test/driver.rb:16:in `initialize'

←[31mF←[0m

Failures:

  1) Static pages Home page should have the content 'Sample App'
     ←[31mFailure/Error:←[0m ←[31mvisit '/static_pages/home'←[0m
     ←[31mArgumentError←[0m:
       ←[31mrack-test requires a rack application, but none was given←[0m
←[36m     # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top
(required)>'←[0m

Finished in 0.001 seconds
←[31m1 example, 1 failure←[0m

Failed examples:

←[31mrspec ./spec/requests/static_pages_spec.rb:7←[0m ←[36m# Static pages Home p
age should have the content 'Sample App'←[0m

我目前的Capybara版本是2.1.0,但我尝试将版本更改为1.1.2并捆绑更新,但也没有工作。 还尝试了不同的语法进行测试。

page.should have_title("Sample App")
page.should have_selector('h1', :text => 'Sample App')
page.should have_selector('title', text: 'Sample App')

我的系统是Windows 7,我的rails版本是4.0.8,Ruby版本是1.9.3。

尝试搜索“机架测试需要机架应用程序,但没有给出”错误,似乎我需要更改,以便机架不是默认驱动程序。 这就是我的配置文件的样子。

# This file is copied to spec/ when you run 'rails generate rspec:install'

require 'capybara/rspec'

RSpec.configure do |config|
  config.include Capybara::DSL
end

0 个答案:

没有答案