Ruby on rails 3 使用designe+请求规格;Rspec2+;斯波克/卫兵
我已经安装了Rspec2+Spork+Guard+Desive 我的档案如下Ruby on rails 3 使用designe+请求规格;Rspec2+;斯波克/卫兵,ruby-on-rails-3,integration-testing,rspec2,guard,spork,Ruby On Rails 3,Integration Testing,Rspec2,Guard,Spork,我已经安装了Rspec2+Spork+Guard+Desive 我的档案如下 #spec_helper.rb Spork.prefork do #code Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f} RSpec.configure do |config| config.extend ControllerMacros, :type => :controller end end
#spec_helper.rb
Spork.prefork do
#code
Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f}
RSpec.configure do |config|
config.extend ControllerMacros, :type => :controller
end
end
Spork.each_run do
# This code will be run each time you run your specs.
FactoryGirl.reload
include ControllerMacros
end
#spec/support/controller_macros.rb
module ControllerMacros
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mapping[:user]
user = FactoryGirl.create(:user)
sign_in user
end
end
end
#spec/support/devise.rb
Spec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
在我的请求规范中
#spec/features/documents_spec.rb
require 'spec_helper'
describe "Documents" do
login_user
describe "GET /documents" do
it "should display document name as sameera CV" do
#spec code
end
end
end
当我运行bundle exec guard时,我得到
1) Documents GET /documents should display document name as sameera CV
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `env' for nil:NilClass
# ./spec/support/controller_macros.rb:4:in `block in login_user'
到目前为止,我已经通过谷歌做了很多修复,但似乎没有任何效果,有人能帮我吗:)
我在
- 轨道3.2.9
- rspec 2.12.0
- 设计2.2.3
任何帮助都将不胜感激尝试将
@request.env[“design.mapping”]=design.mapping[:user]
更改为request.env[“design.mapping”]=design.mapping[:user]
在spec/support/controller\u macros.rb
中尝试更改@request.env[“design.mapping”]=design.mapping[:user]
到request.env[“design.mapping”]=design.mapping[:user]
在spec/support/controller\u macros.rb
这里我回答了我自己的问题,我能够找到解决问题的方法
以下是我所做的步骤
1) 从支持目录中删除了controller\u macros.rb
和designe.rb
2) 从spec\u helper.rb
3) 将以下代码添加到
#spec/features/documents_spec.rb
before(:each) do
user = FactoryGirl.create(:user)
visit root_path
fill_in 'user_email', :with => user.email
fill_in 'user_password', :with => user.password
click_button 'Sign in'
end
我相信应该有一种更优雅的方式(如Devage wiki中所述),但这是可行的:)在这里,我回答了自己的问题,我能够找到解决问题的方法 以下是我所做的步骤 1) 从支持目录中删除了
controller\u macros.rb
和designe.rb
2) 从spec\u helper.rb
3) 将以下代码添加到
#spec/features/documents_spec.rb
before(:each) do
user = FactoryGirl.create(:user)
visit root_path
fill_in 'user_email', :with => user.email
fill_in 'user_password', :with => user.password
click_button 'Sign in'
end
我相信应该有一种更优雅的方式(如Devage wiki中所述),但这是有效的:)感谢您的回复,它不起作用,当我更改它时,它说未定义的局部变量或方法“请求”#感谢您的回复,它不起作用,当我更改它时,它说未定义的局部变量或方法“请求”#