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.
rails test
Run options: --seed 21696
# Running:
/home/rubys/.rvm/gems/ruby-2.4.0/gems/sass-3.4.23/lib/sass/util.rb:1109: warning: constant ::Fixnum is deprecated
/home/rubys/.rvm/gems/ruby-2.4.0/gems/sass-3.4.23/lib/sass/util.rb:1109: warning: constant ::Fixnum is deprecated
..........E
Error:
ProductsControllerTest#test_should_get_index:
ActionView::Template::Error: The asset "ruby.png" is not present in the asset pipeline.
app/views/products/index.html.erb:10:in `block in _app_views_products_index_html_erb___2822750051138081692_36226020'
app/views/products/index.html.erb:6:in `_app_views_products_index_html_erb___2822750051138081692_36226020'
test/controllers/products_controller_test.rb:20:in `block in <class:ProductsControllerTest>'
bin/rails test test/controllers/products_controller_test.rb:19
.E
Error:
StoreControllerTest#test_should_get_index:
ActionView::Template::Error: The asset "ruby.png" is not present in the asset pipeline.
app/views/store/index.html.erb:7:in `block in _app_views_store_index_html_erb__3723583924437596326_30840360'
app/views/store/index.html.erb:5:in `_app_views_store_index_html_erb__3723583924437596326_30840360'
test/controllers/store_controller_test.rb:5:in `block in <class:StoreControllerTest>'
bin/rails test test/controllers/store_controller_test.rb:4
Finished in 0.623046s, 20.8652 runs/s, 49.7556 assertions/s.
13 runs, 31 assertions, 0 failures, 2 errors, 0 skips
Make sure the images exists
touch app/assets/images/ruby.png
Rerun the tests.
rails test
Run options: --seed 28476
# Running:
.............
Finished in 0.523135s, 24.8502 runs/s, 63.0813 assertions/s.
13 runs, 33 assertions, 0 failures, 0 errors, 0 skips
Add tests for layout, product display, and formatting, using counts, string comparisons, and regular expressions.
edit test/controllers/store_controller_test.rb
require 'test_helper'
class StoreControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get store_index_url
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/FixtureSet.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.
rails test:controllers
Run options: --seed 14637
# Running:
........
Finished in 0.271558s, 29.4596 runs/s, 51.5543 assertions/s.
8 runs, 14 assertions, 0 failures, 0 errors, 0 skips
8.5 Iteration C5 - Caching 8.3 Iteration C3: Use a Helper to Format the Price