我目前正在尝试自学如何使用rails进行rspec测试。我在这里关注博客的指南, http://everydayrails.com/2012/03/12/testing-series-rspec-setup.html 并且到了我无法运行命令的程度 “rails g rspec:install”
我最终得到了许多问题
/Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `devise' for Install (call 'Install.connection' to establish a connection):Class (NoMethodError) from /Users/kdweber89/Desktop/railspractice/firstApp/myApp/app/models/install.rb:4:in `<class:Install>'
from /Users/kdweber89/Desktop/railspractice/firstApp/myApp/app/models/install.rb:1:in `<top (required)>'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:457:in `load'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:457:in `block in load_file'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:647:in `new_constants_in'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:456:in `load_file'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:354:in `require_or_load'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:494:in `load_missing_constant'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:184:in `const_missing'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/inflector/methods.rb:261:in `const_get'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/inflector/methods.rb:261:in `block in constantize'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/inflector/methods.rb:259:in `each'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/inflector/methods.rb:259:in `inject'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/inflector/methods.rb:259:in `constantize'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:566:in `get'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:597:in `constantize'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise.rb:301:in `get'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise/mapping.rb:80:in `to'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise/mapping.rb:75:in `modules'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise/mapping.rb:92:in `routes'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise/mapping.rb:159:in `default_used_route'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise/mapping.rb:69:in `initialize'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise.rb:335:in `new'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise.rb:335:in `add_mapping'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise/rails/routes.rb:224:in `block in devise_for'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise/rails/routes.rb:223:in `each'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/devise-3.3.0/lib/devise/rails/routes.rb:223:in `devise_for'
from /Users/kdweber89/Desktop/railspractice/firstApp/myApp/config/routes.rb:2:in `block in <top (required)>'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:410:in `draw'
from /Users/kdweber89/Desktop/railspractice/firstApp/myApp/config/routes.rb:1:in `<top (required)>'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:40:in `each'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/file_update_checker.rb:75:in `call'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/file_update_checker.rb:75:in `execute'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:27:in `updater'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
from /Users/kdweber89/Desktop/railspractice/firstApp/myApp/config/environment.rb:5:in `<top (required)>'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/spring-1.3.6/lib/spring/application.rb:92:in `preload'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/spring-1.3.6/lib/spring/application.rb:143:in `serve'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/spring-1.3.6/lib/spring/application.rb:131:in `block in run'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/spring-1.3.6/lib/spring/application.rb:125:in `loop'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/spring-1.3.6/lib/spring/application.rb:125:in `run'
from /Users/kdweber89/.rvm/gems/ruby-2.1.5/gems/spring-1.3.6/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/kdweber89/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
我的models / install.rb页面是
class Install < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
我的Gemfile页面在这里。
source 'https://rubygems.org'
gem 'rails', '4.2.1'
gem 'haml', '~> 4.0.5'
gem 'bootstrap-sass', '~> 3.2.0.2'
gem "spring-commands-rspec"
gem 'simple_form', '~> 3.0.2'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'devise'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring', group: :development
end
group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
end
group :test do
gem 'faker'
gem 'capybara'
gem 'guard-rspec'
gem 'launchy'
end
我的任何简单路线都是
Rails.application.routes.draw do
devise_for :installs
resources :pins
root "pins#index"
end
这是我的application.rb文件
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
module MyApp
class Application < Rails::Application
config.active_record.raise_in_transactional_callbacks = true
end
end
老实说,我不确定还需要展示什么,但如果有人能为我快速浏览一下,我会非常感激。
答案 0 :(得分:0)
确保在群组之外有
gem "devise"
devise_for路由助手由设计宝石提供。
不要忘记运行bundle install
将其安装到项目中