加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – rails rspec http基本认证测试

发布时间:2020-12-17 04:05:24 所属栏目:百科 来源:网络整理
导读:如何使用rspec2 amp ;;使用http basic auth测试登录到rails 3.1 app水豚? 我正在使用这个; describe "GET 'index'" do it "should be successful" do request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("username:password") get 'index' r
如何使用rspec2& amp ;;使用http basic auth测试登录到rails 3.1 app水豚?

我正在使用这个;

describe "GET 'index'" do
      it "should be successful" do
        request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("username:password")
        get 'index'
        response.should be_success
      end
    end

但它给了我这个错误;

NoMethodError:
            undefined method `env' for nil:NilClass

解决方法

Capybara内置 Rack::Test.

因此,您可以在发出请求之前使用Rack::Test::Session.basic_authorize method设置Authorization HTTP header field.

basic_authorize 'username','password'
get 'index'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读