Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法';环境';零级:零级_Ruby On Rails_Rspec_Devise - Fatal编程技术网

Ruby on rails 未定义的方法';环境';零级:零级

Ruby on rails 未定义的方法';环境';零级:零级,ruby-on-rails,rspec,devise,Ruby On Rails,Rspec,Devise,这就是我的spec文件的样子:spec/api/v1/projects\u spec.rb require "spec_helper" describe "/api/v1/projects", :type => :api do context "projects viewable by this user" do it "JSON" do end end end module ApiHelper include Rack::Test::Methods de

这就是我的spec文件的样子:
spec/api/v1/projects\u spec.rb

require "spec_helper"

describe "/api/v1/projects", :type => :api do
  context "projects viewable by this user" do
   it "JSON" do
   end
  end
end
module ApiHelper
  include Rack::Test::Methods

  def app
   Rails.application
  end
end

RSpec.configure do |c|
  c.include ApiHelper, :type => :api
end
它包含了更多的内容,但我删除了很多行,试图找到如下错误,但没有成功:

Failure/Error: Unable to find matching line from backtrace
NoMethodError: undefined method `env' for nil:NilClass
这段代码来自Ryan Bigg的“Rails 3 in Action”。它包含的唯一其他文件是:
spec/support/api/helper.rb

require "spec_helper"

describe "/api/v1/projects", :type => :api do
  context "projects viewable by this user" do
   it "JSON" do
   end
  end
end
module ApiHelper
  include Rack::Test::Methods

  def app
   Rails.application
  end
end

RSpec.configure do |c|
  c.include ApiHelper, :type => :api
end
在过去的一个小时里,我一直在用谷歌搜索这个错误,我发现的最近的一个错误是,结果我删除了使用designe::Test_Helpers的代码。可悲的是,它仍然不起作用

任何帮助都将不胜感激。非常感谢你

堆栈跟踪
您仍然在某处包含Desive::TestHelpers。检查并查看正在加载的“spec\u helper”是什么。

您可以指定它的类型,而不仅仅包括designe Test helper,以便它不包括在路由规范中:

  config.include Devise::TestHelpers, :type => :helper
  config.include Devise::TestHelpers, :type => :controller

添加更多的堆栈跟踪会很有帮助。顺便说一句,如果您想将Desive与Capybara一起使用,可以。Spec\u Helper正在调用designe::TestHelpers。在编写测试时,我应该如何解决这个问题?只需在使用它们的规范中包含designe::TestHelpers。您不必为所有规格全局包含它们。例如,将
spec\u helper.rb
放在一边,在一个测试文件
some\u controller\u spec.rb
中,确保调用
include designe::TestHelpers
您还需要做一些其他的设置,所以为了保持测试干燥,我制作了ActionController::TestCase的一个特定于designe的子类