2014-06-15 46 views
0

我試圖在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> 

太感謝了。任何人想幫助我!謝謝! ;)

回答

0

也許你沒有定義capybara或其他驅動程序。然後嘗試content而不是text

page.should have_selector('h1', :content => 'Sample App') 
+0

非常感謝您的幫助!不幸的是,這並沒有奏效。我得到了:ArgumentError: 無效的鍵:內容,應該是:text,:visible,:between,:count,:maximum,:minimum,:exact,:match,:wait – iammyr

+0

那麼,仍然不起作用? – zishe

+1

都能跟得上:/我試圖找出如何在目前使用撬,如其他意見建議;) – iammyr

1

你應該首先從請求移動規範,以功能的文件夾see changes in capybara

我想這將修復它(記得有一個類似) 如果有不對它進行調試在Firefox撬和硒司機

#Gemfile 
    gem 'pry-rails' 

    #spec 
    it "should have the h1 'Sample App'", :js => true do 
    visit '/pages/home' 
    binding.pry 
    page.should have_selector('h1', :text => 'Sample App') 
end 

的Firefox應該啓動並在調試模式下呈現 頁上,然後檢查水豚選擇

page.all(:css, 'h1') 
+0

檢查關於移動到文件夾功能感謝 –

+0

百萬user1035375規範的編輯!不幸的是,將測試移至新的規格/功能文件夾並不能解決問題:它仍然失敗。非常感謝提撬和硒,因爲我已經通過搜索周圍信息學到了很多東西。但是,到目前爲止,我已經在示例類上運行pry,但不在rspec上運行。搞清楚如何做到這一點... – iammyr

相關問題