在我之前的同一篇文章中,我没有解决我的问题并没有得到很多答案,所以我正在重新发布我的问题以尝试获得更多帮助。
我正在关注Michael Hartl的教程,而在3.2.1中我们正在测试服务器:
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
当我在控制台中输入“bundle exec rspec spec / requests / static_pages_spec.rb”时,我收到一堆错误,如下所示:
root@KyleBuntu:~/Desktop/Rails/sample_app# bundle exec rspec spec/requests/static_pages_spec.rb
/home/verendus/Desktop/Rails/sample_app/spec/requests/static_pages_spec.rb:1:in `require': /home/verendus/Desktop/Rails/sample_app/spec/spec_helper.rb:44: syntax error, unexpected tIDENTIFIER, expecting end-of-input (SyntaxError)
:DSL to config.include Capybara::DSL
^
from /home/verendus/Desktop/Rails/sample_app/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
from /home/verendus/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /home/verendus/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /home/verendus/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /home/verendus/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /home/verendus/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /home/verendus/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /home/verendus/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
我知道我应该得到一个错误,但在书中,作者收到的错误要短得多,而且不同。 (评论中的链接)
我已经更改了rspec_helper.rb文件以添加Capybara DSL,但我不确定这是否是问题,如果我做了或没有正确输入它。我对Rails,Ruby和编码/ Linux系统(我正在使用Ubuntu)也很陌生,所以如果需要什么,那就问问。
评论中的Github链接。
答案 0 :(得分:0)
您似乎在spec_helper.rb:44中有一个已被部分删除并因此取消注释的注释行。
:DSL to config.include Capybara::DSL
# This file is copied to spec/ when you run 'rails generate rspec:install'
您可能希望或可能不想config.include Capybara::DSL
,但:DSL to
部分是导致语法错误的原因。
此外,您在下面的行中有一些奇怪的.
句点,这可能会导致更多语法错误。您甚至可能希望再次运行rails generate rspec:install
以完全重新生成文件。
答案 1 :(得分:0)
您的spec_helper.rb文件中有错误。
这一行
:DSL to config.include Capybara::DSL
应该删除。相反,如果您想要包含Capybara::DSL
,则应添加
config.include Capybara::DSL
在RSpec::configure do |config|
区块内。