capybara:post,将请求目录的名称更改为功能时,get方法不起作用 [英] capybara: post, get methods not working when changing name of requests directory to features

查看:189
本文介绍了capybara:post,将请求目录的名称更改为功能时,get方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到最新版本的水豚之后,我的所有访问方法都停止工作,因此我遵循一些人员提出的解决方案,将请求规范目录重命名为功能。现在我的访问方法再次运行,但请求规范中的任何get或post方法都会导致此错误:

 未定义方法`get' for#< RSpec :: Core :: ExampleGroup :: Nested_1 :: Nested_1 :: Nested_1 :: Nested_1 :: Nested_1:0x007f9cce9adc20> 

以下是触发错误的代码:

 描述获得帖子在{get(forum_posts_path)} 
之前做
它应该用200做回应do
response.response_code.should == 200
end
end

对此的任何解决方法?

解决方案

您不会将 spec / requests 目录重命名为 spec / features




  • 使用Capybara DSL( visit 等),并且通常针对页面进入 spec / features 中。
  • 测试使用机架测试DSL( get 等),并且通常针对响应进入 spec / requests 答案的详细信息,特别是外壳rnal链接那里。


    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?

    解决方案

    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.

    这篇关于capybara:post,将请求目录的名称更改为功能时,get方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆