【问题标题】:Minitest and Fixtures: Passing in the correct params?Minitest 和 Fixtures:传递正确的参数?
【发布时间】:2019-01-11 17:01:47
【问题描述】:

所以我试图在 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>'

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

【问题讨论】:

    标签: ruby-on-rails testing minitest


    【解决方案1】:

    解决者:

    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
    

    【讨论】:

      猜你喜欢
      • 2021-06-14
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      • 2014-11-24
      相关资源
      最近更新 更多