Agile Web Development with Rails, Edition 4

Agile Web Development with Rails, Edition 4

8.5 Playtime 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.

rake test
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
.....
Finished in 0.300459 seconds.
 
5 tests, 23 assertions, 0 failures, 0 errors, 0 skips
 
Test run options: --seed 13206
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
........
Finished in 0.682874 seconds.
 
8 tests, 11 assertions, 0 failures, 0 errors, 0 skips
 
Test run options: --seed 39268

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
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
........
Finished in 0.967558 seconds.
 
8 tests, 15 assertions, 0 failures, 0 errors, 0 skips
 
Test run options: --seed 34989

8.5 Playtime 8.3 Iteration C3: Use a Helper to Format the Price