我试图通过rspec和capybara登录用户。这是我第一次编写自己的测试,而且我不确定问题是什么,就像我点击我的应用程序一样,它工作正常。似乎问题是RSPEC没有正确填写字段,或者没有点击链接或按钮,但我不确定哪个或如何查找。
这是测试(编辑添加此内容):
it "logs the user in and redirects them to speakeasy home on success" do
sign_up_as_hello_world
page.should have_content 'INSTANT MACHINE TRANSLATION'
end
这是失败
1) Sign up logs the user in and redirects them to speakeasy home on success
Failure/Error: page.should have_content 'INSTANT MACHINE TRANSLATION'
expected to find text "INSTANT MACHINE TRANSLATION" in "Speakeasy Technology + Humanity Sign In Invalid username or password New users start out with $5 demo credit Sign Up"
# ./spec/features/auth_spec.rb:40:in `block (2 levels) in <top (required)>'
这是&#34;注册&#34;我的规范助手中的方法
def sign_up(username)
visit "/session/new"
click_link "signUpLink"
fill_in "username", with: username
fill_in "email", with: 'email@email.com'
fill_in "password", with: 'abcdef'
find('input[id="submitButton"]').click
end
我也试过这个作为最后一行,但它不起作用
click_button "Sign Up"
表单的html就在这里(点击注册链接会更改提交按钮的值以注册:
<form class="login" action="<%= session_url %>" method="post" id="mainForm">
<%= auth_token_input%>
<input type="text" placeholder="Username" name="user[username]" id="username"/>
<input type="text" placeholder="Email" name="user[email]" id="email"/>
<input type="password" placeholder="Password" name="user[password]" id="password"/>
<input type="submit" value="Sign In" class="btn btn-success btn-sm" id="submitButton"/>
<div style="text-align:center">
<p>New users start out with $5 demo credit</p>
<a href="" class="register" id="signUpLink">Sign Up</a>
</div>
</form>