Sha256: 5ae2e693ab8a27b7eb24572bd559825368ef720ca3d03d679773c3a1a90bb3cf

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require 'helper'

class TestClassMethods < Test::Unit::TestCase
    class Car
        attr_accessor :make, :model
        
        def initialize(make, model)
            @make, @model = make, model
        end
        
        class_rules do
            rule(/new_([a-z]+)_(.+)/) do |make, model|
                
                make.capitalize!
                model = model.split('_').inject(''){ |result, word|
                    result << word.capitalize + ' '
                }.strip
                new(make, model)
            end
        end
    end
    
    should 'be a Ford F150' do
        @car = Car.new_ford_f150
        assert_equal @car.make, 'Ford'
        assert_equal @car.model, 'F150'
    end

    should 'be a Ford Mustang' do
        @car = Car.new_ford_mustang
        assert_equal @car.make, 'Ford'
        assert_equal @car.model, 'Mustang'
    end
    
    should 'be a Pontiac GTO' do
        @car = Car.new_pontiac_gto
        @car.model.upcase!
        assert_equal @car.make, 'Pontiac'
        assert_equal @car.model, 'GTO'
    end
    
    should 'be a Toyota Camry' do
        @car = Car.new_toyota_camry
        assert_equal @car.make, 'Toyota'
        assert_equal @car.model, 'Camry'
    end
    
    should 'be a Hyundai Santa Fe' do
        @car = Car.new_hyundai_santa_fe
        assert_equal @car.make, 'Hyundai'
        assert_equal 'Santa Fe', @car.model
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rulebook-0.3.3 test/test_class_methods.rb
rulebook-0.3.2 test/test_class_methods.rb
rulebook-0.3.1 test/test_class_methods.rb