capybara: post, get methods not working when changing name of requests directory to features

我与影子孤独终老i 提交于 2019-12-13 04:26:45

问题


After upgrading to the latest version of Capybara, all of my visit methods stopped working so I followed a solution presented by some people which was to rename the requests spec directory to "features". Now my visit methods are working again but any get or post method in a request spec causes this error:

undefined method `get' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1::Nested_1:0x007f9cce9adc20>

Here's the code that triggers the error:

describe "getting posts" do
    before { get(forum_posts_path) }
    it "should respond with a 200" do
        response.response_code.should == 200
    end
end

Any workaround for this?


回答1:


You don't rename the spec/requests directory to spec/features: you have both:

  • Tests that use the Capybara DSL (visit etc) and usually assert against page go in spec/features.
  • Tests that use the rack-test DSL (get etc) and usually assert against response go in spec/requests

See this StackOverflow answer for details, specifically the external links there.



来源:https://stackoverflow.com/questions/14473810/capybara-post-get-methods-not-working-when-changing-name-of-requests-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!