0

I have a test I am doing where I am testing the available dates that my website shows for the datepicker. The datepicker is supposed to make the next X business days available, and ignore weekends and holidays.

I was testing two scenarios, 1 that looks at pickup dates for people who place orders (on July 1st) and choose to pick up, where the next 5 business days(July 2nd, 3rd, 5th, 8th, and 9th) are available. I brute force tested it with the following rspec/capybara code and it passes no problem:

find("#datepicker_").click

find(".ui-datepicker-group-first").should_not have_link("1")
find(".ui-datepicker-group-first").should have_link("2") 
find(".ui-datepicker-group-first").should have_link("3")
find(".ui-datepicker-group-first").should_not have_link("4")
find(".ui-datepicker-group-first").should have_link("5")
find(".ui-datepicker-group-first").should_not have_link("6")
find(".ui-datepicker-group-first").should_not have_link("7")
find(".ui-datepicker-group-first").should have_link("8")
find(".ui-datepicker-group-first").should have_link("9")
find(".ui-datepicker-group-first").should_not have_link("10")

The next test deals with shipping the item instead of picking up, so with a 5 day shipping time, the available dates should be the 3rd, 5th, 8th, 9th, 10th, 11th, 12th, 15th, and 16th. However, my test (same as above, but looking at range between 2nd-17th) is failing, even though the datepicker shows only the correct dates that I am expecting as available. For some reason, it's saying that the 2nd and 6th have links (i.e. selectable dates) when they clearly do not. An example of the error cna be seen below:

Failures:

  1) cart functionality should make the right delivery dates available in the cart
     Failure/Error: find(".ui-datepicker-group-first").should_not have_link("2")
       expected #has_link?("2") to return false, got true
     # ./cart_functionality_spec.rb:100:in `block (2 levels) in <top (required)>

I took a screenshot of what the browser looked like during the test when I froze the test with Pry right before it did the check with rpsec. The screenshot can be seen below

Screenshot of datepicker available dates

What's weird is that the July 4th, other weekends such as July 7th, and July 17th don't trigger this error. If I comment out the test for the 2nd and the 6th, the test passes. Does anyone know why this is happening?

I'm working with: Capybara 2.1, Rspec-rails 2.14.0

4

1 回答 1

0

我发现了这个问题。由于第 2 个不是链接,第 12 个是链接,所以当我使用代码时

find(".ui-datepicker-group-first").should_not have_link("2")

它检测到日期“12”的链接。同样的情况发生在 6 日和 16 日。我将测试更改为:

find(".ui-datepicker-group-first").should_not have_link(/^(2)$/)

这解决了问题。

于 2013-08-05T18:52:12.787 回答