1
我想指出一个Users
控制器,使用RSpec 3.1.7,我不断收到unexpected end-of-input SyntaxError
。我结束了“剥离”整个控制器的第一describe
,正好看到哪一行导致了问题,像这样:“意外的输入结束,期待keyword_end(SyntaxError)”RSpec 3,Rails 4.1.6,Ruby 2.0
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
我运行:
- 红宝石2.0
- 的Rails 4.1.6
- RSpec的3
语法错误在控制器文件中,而不是规范。 – 2015-02-05 21:24:19
在错误消息中,我们可以看到:[my app path] /app/controllers/users_controller.rb:20:语法错误。你有没有检查你的用户控制器(在第20行左右)。也许'结局'缺失。 – 2015-02-05 21:25:31
哦,男孩......我是一个小菜鸟。当然...谢谢! – 2015-02-05 21:26:33