我正在收回rails 3.0.3中使用devise和localized_routes的项目。该项目没有任何测试,所以我用rspec和工厂女孩写了一个非常简单的测试。
执行测试时,我收到错误(与我认为的测试无关):
rspec spec/helpers/application_helper_spec.rb
/Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:163:in `define_hash_access': compile error (SyntaxError)
/Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:161: syntax error, unexpected '-', expecting '\n' or ';'
... hash_for_new_user_session_en-ca_path(options = nil) ...
^
/Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:163: syntax error, unexpected kEND, expecting $end
end ...
^
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:151:in `define_named_route_methods'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:149:in `each'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:149:in `define_named_route_methods'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:100:in `[]='
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:300:in `add_route_without_i18n'
from /Users/pl/src/dialogcube/vendor/plugins/localized_routes/lib/localized_routes.rb:21:in `add_route'
from /Users/pl/src/dialogcube/vendor/plugins/localized_routes/lib/localized_routes.rb:12:in `each'
from /Users/pl/src/dialogcube/vendor/plugins/localized_routes/lib/localized_routes.rb:12:in `add_route'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:262:in `match'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1112:in `match'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1297:in `match'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1094:in `match'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1015:in `member'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:525:in `scope'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1014:in `member'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1199:in `with_scope_level'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1013:in `member'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1094:in `match'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1297:in `match'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:383:in `map_method'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:312:in `get'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:206:in `devise_session'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:898:in `resource'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1208:in `resource_scope'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:525:in `scope'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1207:in `resource_scope'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1199:in `with_scope_level'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1206:in `resource_scope'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:897:in `resource'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:205:in `devise_session'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:157:in `send'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:157:in `devise_for'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:157:in `each'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:157:in `devise_for'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:237:in `with_devise_exclusive_scope'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:156:in `devise_for'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:197:in `devise_scope'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:661:in `constraints'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:525:in `scope'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:661:in `constraints'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:196:in `devise_scope'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:154:in `devise_for'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:136:in `each'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails/routes.rb:136:in `devise_for'
from /Users/pl/src/dialogcube/config/routes.rb:10
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:233:in `instance_exec'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:233:in `draw'
from /Users/pl/src/dialogcube/config/routes.rb:1
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:227:in `load_dependency'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/application.rb:127:in `each'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/devise-1.1.5/lib/devise/rails.rb:17
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:34:in `call'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:43:in `run_load_hooks'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/application/finisher.rb:40
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `run_initializers'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/application.rb:77:in `send'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
from /Users/pl/src/dialogcube/config/environment.rb:5
from /Users/pl/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:54:in `gem_original_require'
from /Users/pl/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:54:in `require'
from /Users/pl/src/dialogcube/spec/spec_helper.rb:3
from /Users/pl/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:54:in `gem_original_require'
from /Users/pl/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:54:in `require'
from /Users/pl/src/dialogcube/spec/helpers/application_helper_spec.rb:1
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `load'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `load_spec_files'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `map'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `load_spec_files'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:18:in `run'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:80:in `run_in_process'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:69:in `run'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:10:in `autorun'
from /Users/pl/.rvm/gems/ruby-1.8.7-p334/bin/rspec:19
application_helper_spec.rb:
require 'spec_helper'
describe ApplicationHelper do
it 'should return a analytics tag' do
s = Factory.build(:analytics_setting)
result = analytics_tag
result.should_not be_nil
end
end
我的spec_helper.rb:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'faker'
require 'factory_girl'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
end
(部分)我的route.rb: Dialogcube :: Application.routes.draw做
# Omniauth
match '/auth/:provider/callback' => 'authentications#create', :i18n => false
match '/auth/external/:provider' => 'authentications#show', :i18n => false
# Public
devise_for :users,
:path => 'auth',
:controllers => {
:registrations => 'registrations',
:sessions => 'sessions',
:passwords => 'passwords'
}
resources :users do
put :follow_tag, :on => :member
put :unfollow_tag, :on => :member
resources :entries
end
我无法弄清楚发生了什么,或者为什么在那时会出现编译器错误。看来,根据生成的方法,语言环境是en-ca,并且短划线字符在某种程度上搞砸了代码的某些部分。
我应该看哪些线索?
答案 0 :(得分:0)
我认为它希望语言环境为en_ca
而不是en-ca
。