“意外的输入结束,期待 keyword_end(语法错误)”RSpec 3,Rails 4.1.6,Ruby 2.0

" unexpected end-of-input, expecting keyword_end (SyntaxError)" RSpec 3, Rails 4.1.6, Ruby 2.0

我正在尝试指定一个 Users 控制器,使用 RSpec 3.1.7,并且我不断得到 unexpected end-of-input SyntaxError。我结束了 "stripping" 整个控制器到第一个 describe,只是为了看看是哪一行导致了这个问题,像这样:

require 'rails_helper'

RSpec.describe UsersController, :type => :controller do

end

这是确切的错误:

[my ruby path]lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require': [my app path]/app/controllers/users_controller.rb:20: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
 from [my ruby path]lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:348:in `require_or_load'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:480:in `load_missing_constant'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:180:in `const_missing'
 from [my app path]/spec/controllers/users_controller_spec.rb:3:in `<top (required)>'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `each'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96:in `setup'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
 from [my ruby path]lib/ruby/gems/2.0.0/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
 from [my ruby path]bin/rspec:23:in `load'
 from [my ruby path]bin/rspec:23:in `<main>'

这是我的rails_helper.rb

ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'ffaker'

ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|
  # Factory_Girl Init
  config.include FactoryGirl::Syntax::Methods

  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = false
  config.infer_spec_type_from_file_location!

  # DatabaseClener config
  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.strategy = :transaction
  end

  config.before(:each, :js => true) do
    DatabaseCleaner.strategy = :truncation
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end
end

这是我的 'spec_helper.rb'

RSpec.configure do |config|

  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end
end 

我是 运行:

语法错误似乎在您的控制器文件中,而不是在控制器规范或规范帮助程序中。

/app/controllers/users_controller.rb:20: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)

您可以使用 -c ruby 标志检查单个文件的语法。

$ ruby -c app/controllers/users_controller.rb 
Syntax OK

输出将声明语法正确,或者会向您提供类似于您当前收到的错误消息。