2013-12-11 121 views
1

需要檢查需要一個Rspec的匹配當前URL

describe "SEO Error" do 
    it "URL" do 
     visit 'http://localhost:4000/' 
     current_path.should == 'http://localhost:4000/' 
    end 
end 

遇到錯誤當前URL像

Failure/Error: current_path.should == 'http://localhost:4000/' 
    expected: "http://localhost:4000/" 
     got: "/" (using ==) 

任何想法?

回答

1

剛遇到同樣的問題。像這樣解決它自己:

expect(expected_path).to have_content(current_path) 

P.S.請注意,自從您提出問題以來,已經過了相當長的時間,現在我使用的更新版本的rspec使用expect而不是should

+0

很好的答案。我認爲'expected_pa​​th'和'current_path'應該交換。 – 23inhouse