如何在Rails中为要素规范添加请求方法?

时间:2018-05-07 22:32:20

标签: ruby-on-rails rspec

我有一个名为test_feature_spec.rb的简单测试功能:

(这只是为了解决这个问题......实际规格要长得多,实际的功能规格)

require "features_helper"

RSpec.feature "Simple Feature", type: :feature do
  scenario "a test scenario" do
    get "/"
  end
end

我可以做各种各样的Rails-y事情,包括水豚驱动的东西(比如visit such_n_such_path)。但是上面的崩溃:

Failures:

  1) Simple Feature a test scenario
     Failure/Error: get "/"

     NoMethodError:
       undefined method `get' for #<RSpec::ExampleGroups::SimpleFeature:0x000000011a799788>
       Did you mean?  gets
                      gem

如果我只是将其从type: :feature更改为type: :request,那就可以了:

> rspec spec/features/test_feature_spec.rb
.

Finished in 0.64913 seconds (files took 5.82 seconds to load)
1 example, 0 failures

似乎与type =&gt; request Rails或Rspec加载一些东西以允许调用控制器路由,但它没有type =&gt; feature

有没有办法加载这些辅助方法(例如getpost等),但仍将该功能保留为type: :feature

我知道我可以将其更改为type: :request技术上这些是功能规格,即使对于其中一些,要设置一些状态或做任何事情,他们需要调用某些网址。

1 个答案:

答案 0 :(得分:0)

RSpec.configure do |config| config.include FeaturesHelper, :type => :request end 中,您可以尝试:

{{1}}
相关问题