8.5 Iteration C5 - Caching 8.3 Iteration C3: Use a Helper to Format the Price
Demonstrate use of assert_select to test views.
Verify that the tests still pass.
rake test
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/rake_test_loader
Started
ProductTest:
PASS image url (0.20s)
PASS product attributes must not be empty (0.00s)
PASS product is not valid without a unique title (0.00s)
PASS product is not valid without a unique title - i18n (0.00s)
PASS product price must be positive (0.00s)
Finished in 0.213916 seconds.
5 tests, 23 assertions, 0 failures, 0 errors, 0 skips
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/rake_test_loader
Started
ProductsControllerTest:
PASS should create product (0.20s)
PASS should destroy product (0.01s)
PASS should get edit (0.07s)
PASS should get index (0.01s)
PASS should get new (0.01s)
PASS should show product (0.01s)
PASS should update product (0.01s)
StoreControllerTest:
PASS should get index (0.01s)
Finished in 0.327195 seconds.
8 tests, 11 assertions, 0 failures, 0 errors, 0 skips
Add tests for layout, product display, and formatting, using counts, string comparisons, and regular expressions.
edit test/functional/store_controller_test.rb
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
Review fixure data
edit test/fixtures/products.yml
# Read about fixtures at
# http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
title: MyString
description: MyText
image_url: MyString
price: 9.99
two:
title: MyString
description: MyText
image_url: MyString
price: 9.99
ruby:
title: Programming Ruby 1.9
description:
Ruby is the fastest growing and most exciting dynamic
language out there. If you need to get working programs
delivered fast, you should add Ruby to your toolbox.
price: 49.50
image_url: ruby.png
Show that the tests pass.
rake test:functionals
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/rake_test_loader
Started
ProductsControllerTest:
PASS should create product (0.24s)
PASS should destroy product (0.00s)
PASS should get edit (0.04s)
PASS should get index (0.03s)
PASS should get new (0.01s)
PASS should show product (0.01s)
PASS should update product (0.01s)
StoreControllerTest:
PASS should get index (0.05s)
Finished in 0.403860 seconds.
8 tests, 15 assertions, 0 failures, 0 errors, 0 skips
8.5 Iteration C5 - Caching 8.3 Iteration C3: Use a Helper to Format the Price