Agile Web Development with Rails, Edition 5

8.5 Iteration C5 - Caching 8.3 Iteration C3: Use a Helper to Format the Price

8.4 Iteration C4: Functional Testing

Demonstrate use of assert_select to test views.

Verify that the tests still pass.

rails test
Run options: --seed 25404
 
# Running:
 
.............
 
Finished in 0.398098s, 32.6553 runs/s, 82.8943 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 'nav.side_nav a', minimum: 4 
    assert_select 'main ul.catalog li', 3
    assert_select 'h2', '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: lorem.jpg
  price: 9.99
 
two:
  title: MyString
  description: MyText
  image_url: lorem.jpg
  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.jpg 

Show that the tests pass.

rails test:controllers
Run options: --seed 46783
 
# Running:
 
........
 
Finished in 0.278654s, 28.7095 runs/s, 50.2416 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