Minitest和装置:传递正确的参数?

时间:2019-01-11 17:01:47

标签: ruby-on-rails testing minitest

所以我试图在Rails中创建一个简单的集成测试。我想测试我的登录表单。我只是真的无法弄清楚如何正确传递我的参数。我的.yml文件称为agent.yml。我的装置文件是:

one: 
  first_name: firstNameTest
  last_name: lastNameTest
  email: test@test.com
  encrypted_password: <%= Devise::Encryptor.digest(Agent, '123456') %>

应该没问题。

我尝试过两次测试,但都给我一个错误。第一个,紧随Ruby.docs:

    class FlowsTest < ActionDispatch::IntegrationTest

    test "Login and navigate" do 
        get "/agents/sign_in"
        post "/agents/sign_in", email: agents(:one).email, password: 
        agents(:one).password
        follow_redirect!
      end 

    end

第二个版本:

class FlowsTest < ActionDispatch::IntegrationTest
    test "Login and navigate" do 
    get "/agents/sign_in"
    post "/agents/sign_in", agent: {email: agents(:one).email, password: '123456'}
    follow_redirect!
  end 

end

都抛出一个错误:

Error:
FlowsTest#test_Login_and_navigate:
ArgumentError: unknown keywords: email, password
    test/integration/Flows_test.rb:6:in `block in <class:FlowsTest>'

我想我以错误的方式传递了参数。因为应该从固定装置中获取电子邮件和密码,否则我错了吗?有人可以帮忙吗?将不胜感激。预先谢谢大家!

1 个答案:

答案 0 :(得分:0)

解决者:

require 'test_helper'

class FlowsTest < ActionDispatch::IntegrationTest
  fixtures :agents


      def test_login
        get "/agents/sign_in"
        assert_equal 200, status  
        post "/agents/sign_in", params: { email: agents(:one).email,
          password: agents(:one).password }
        follow_redirect!
        assert_equal 200, status
        assert_equal "/", path
      end 
    end