我正在尝试使用带有rspec的capybara来测试我的rails应用程序。我简化了一个问题:
我点击一个链接,然后通过javascript重定向我
window.location="/sports"
我点击了水豚栏上的这个链接,并查找内容为“体育”的页面,但它总是失败。
当我在测试服务器中打开文件并按“提交付款”方法时,我会被带到我的体育页面。当我观察硒测试运行时,我看不到重定向正在进行。
以下是文件:
swipes_spec.rb:
要求'spec_helper'
describe "Swipes" do
describe "can view index page" do
it "has checkout in h2" do
visit swipe_index_path
page.should have_selector("h2", text: "Checkout")
end
it "should have link test js" do
visit swipe_index_path
page.should have_link("test js")
end
it "responds to js", js: true do
visit swipe_index_path
click_link "test js"
page.should have_selector('a', text: "js works")
end
it "responds to button press", js: true do
visit swipe_index_path
click_button "Submit Payment"
wait_until(10) do
page.has_content?("Select a Sport")
end
page.should have_selector('h2', text: "Select")
end
end
end
刷卡/ index.html.erb:
<h2>Checkout</h2>
<span class="payment-errors"></span>
<form action="" method="POST" id="payment-form">
<div class="form-row">
<label>Card Number</label>
<input type="text" size="20" autocomplete="off" id ="card-number" class="card-number"/>
</div>
<div class="form-row">
<label>CVC</label>
<input type="text" size="4" autocomplete="off" class="card-cvc"/>
</div>
<div class="form-row">
<label>Expiration (MM/YYYY)</label>
<input type="text" size="2" class="card-expiry-month"/>
<span> / </span>
<input type="text" size="4" class="card-expiry-year"/>
</div>
<button type="submit" class="submit-button">Submit Payment</button>
</form>
<%= link_to_function "test js", '$(this).html("js works")' %>
<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
<script type="text/javascript">
Stripe.setPublishableKey('pk_xIm00GVAKVLMWmfeR2J8GlmeHcyhL');
$(document).ready(function() {
$("#payment-form").submit(function(event) {
// disable the submit button to prevent repeated clicks
$('.submit-button').attr("disabled", "disabled");
window.location = "/sports";
return false;
});
});
function stripeResponseHandler(status, response) {
if (response.error) {
$('.submit-button').removeAttr("disabled");
//show the errors on the form
$(".payment-errors").html(response.error.message);
} else {
var form$ = $("#payment-form");
// token contains id, last4, and card type
var token = response['id'];
// insert the token into the form so it gets submitted to the server
form$.append("<input type='hidden' name='stripeToken' value='" + token + "'/>");
// and submit
form$.get(0).submit();
}
}
</script>
答案 0 :(得分:-1)
我有一些错误。我跑了gem update
来更新其他一些宝石,这开始工作了。我还下载了QT。其中一件事让一切都快乐。