我試圖在Rails教程之後運行非常簡單的RSpec測試,當它們不應該出現時,它們令人驚訝地失敗。RSpec失敗:頁面應該有標題
Fiona其他地方建議移動app/views/layouts中的application.html.erb文件,但是我已經在那裏了。
Zetetic建議添加「渲染視圖」,但我沒有做任何改變。是
我使用的SW的版本如下:
RVM 26年1月25日
rspec的3.0.1
紅寶石1.9.3p547
Rails 4.1.1
我得到以下失敗消息:從教程
$>rspec spec/requests/pages_spec.rb
F
Failures:
1) Pages Home page should have the h1 'Sample App'
Failure/Error: page.should have_selector('h1', :text => 'Sample App')
expected #has_selector?("h1", {:text=>"Sample App"}) to return true, got false
# ./spec/requests/pages_spec.rb:9:in `block (3 levels) in <top (required)>'
Deprecation Warnings:
Requiring `rspec/autorun` when running RSpec via the `rspec` command is deprecated. Called from /home/iammyr/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'.
Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. Called from /home/iammyr/railsgirls-app/projects/galway_june2014/spec/requests/pages_spec.rb:9:in `block (3 levels) in <top (required)>'.
Failed examples:
rspec ./spec/requests/pages_spec.rb:7 # Pages Home page should have the h1 'Sample App'
一個區別是,而不是生成與「軌道產生static_pages」那些靜態頁面我沒有運行「軌道生成器的網頁首頁幫助」,但不應該與rspec結果無關,恕我直言。
這些文件如下所示。
pages_spec.rb
require 'spec_helper'
describe "Pages" do
render_views
describe "Home page" do
it "should have the h1 'Sample App'" do
visit '/pages/home'
page.should have_selector('h1', :text => 'Sample App')
end
end
end
home.html.erb
<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
This is the home page.
</p>
太感謝了。任何人想幫助我!謝謝! ;)
非常感謝您的幫助!不幸的是,這並沒有奏效。我得到了:ArgumentError: 無效的鍵:內容,應該是:text,:visible,:between,:count,:maximum,:minimum,:exact,:match,:wait – iammyr
那麼,仍然不起作用? – zishe
都能跟得上:/我試圖找出如何在目前使用撬,如其他意見建議;) – iammyr