Answer the question
In order to leave comments, you need to log in
Why does this test pass? And from the book does not pass?
#product.yml
one:
title: MyString
description: MyText
image_url: MyString
price: 99.99
two:
title: MyString
description: MyText
image_url: MyString
price: 99.99
ruby:
title: Programming Ruby 1.9
description: MyText
image_url: MyString.png
price: www
require 'test_helper'
class StoreControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_select '#columns #side a', minimum: 4
assert_select '#main .entry', 3
assert_select 'h3', 'Programming Ruby 1.9'
assert_select '.price', /[\d]+\.\d\d/
end
end
Run options: --seed 45596
# Running:
............
Finished in 0.478399s, 25.0837 runs/s, 81.5220 assertions/s.
12 runs, 39 assertions, 0 failures, 0 errors, 0 skips
one:
title: MyString
description: MyText
image_url: MyString
price: 99.99
two:
title: MyString
description: MyText
image_url: MyString
price: 99.99
ruby:
title: Programming Ruby 1.9
description: MyText
image_url: MyString.png
price: 99.99
require 'test_helper'
class StoreControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_select '#columns #side a', minimum: 4
assert_select '#main .entry', 3
assert_select 'h3', 'Programming Ruby 1.9'
assert_select '.price', /\$[,\d]+\.\d\d/
end
end
Run options: --seed 3724
# Running:
...........F
Finished in 0.483193s, 24.8348 runs/s, 80.7131 assertions/s.
1) Failure:
StoreControllerTest#test_should_get_index [/home/beerdy/Dev/depot/test/controllers/store_controller_test.rb:10]:
<(?-mix:\$[,\d]+\.\d\d)> expected but was
<99.99>..
Expected 0 to be >= 1.
12 runs, 39 assertions, 1 failures, 0 errors, 0 skips
Answer the question
In order to leave comments, you need to log in
In the first case, the regular expression [\d]+\.\d\d
captures the price in the format "number.number".
In the second case, the regular expression \$[,\d]+\.\d\d
requires a dollar sign before the price, like "$number.number". To pass the test in the second case, you need to add a dollar sign to the price or change the regular expression to[\d]+\.\d\d
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question