我已经像这样安装了rspec-rails并创建了一个文件static_pages_spec.rb
gem list
272 rails g rspec:install
274 rails generate integrateion_test static_pages
之后我在static_pages_soec,rb
中写下了这段代码require 'spec_helper'
describe "StaticPages" do
describe "Home page" do
it "should have the content 'sample app'" do
visit '/static_pages/home'
page.should have content('Sample App')
end
end
end
之后运行此命令但收到错误
jaskaran@jaskaran-Vostro-1550:~/rails_project$ bundle exec rspec spec/requests/static pages spec.rb
/home/jaskaran/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.14.8/lib/rspec
/core/configuration.rb:896:in `load': cannot load such file -- /home/jaskaran/rails_project/pages (LoadError)
from /home/jaskaran/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /home/jaskaran/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `each'
from /home/jaskaran/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /home/jaskaran/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22:in `run'
from /home/jaskaran/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
from /home/jaskaran/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'
答案 0 :(得分:0)
看起来您的代码中存在拼写错误。
page.should have content('Sample App')
应该是
page.should have_content('Sample App')
如果您对Mike Hartl的教程有任何疑问,可以随时查看完整版here
答案 1 :(得分:0)
您正在运行的命令不正确。
你创建了一个名为static_pages_spec.rb
的文件(至少我希望你做过 - 你的问题充满了拼写错误)但是你的命令正在寻找static pages spec.rb
通过添加下划线来修复命令。