Sha256: 8f6cad511c9246a2b00185ae8238c59e31493cf11f3c7333bb767ebce04f802c

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require File.expand_path(File.dirname(__FILE__)) + '/helper'

class TestParameters < Test::Unit::TestCase
  
  def setup
    @class = Class.new do
      include Tracksperanto::Parameters
    end
  end
  
  def test_parameters_empty_by_default
    assert_equal [], @class.parameters
  end
  
  def test_parameter_initialization
    flexmock(@class).should_receive(:attr_accessor).once.with(:foo)
    @class.parameter :foo
    assert_equal 1, @class.parameters.length
    
    first_param = @class.parameters[0]
    assert_equal :foo, first_param.name
    assert_nil first_param.desc
  end

  def test_parameter_initialization_with_safety
    flexmock(@class).should_receive(:attr_accessor).once.with(:foo)
    flexmock(@class).should_receive(:safe_reader).once.with(:foo)
    @class.parameter :foo, :required => true
  end
  
  def test_parameter_initialization_with_cast
    flexmock(@class).should_receive(:attr_accessor).once.with(:foo)
    flexmock(@class).should_receive(:cast_to_junk).once.with(:foo)
    @class.parameter :foo, :cast => :junk
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tracksperanto-4.1.2 test/test_parameters.rb
tracksperanto-4.1.0 test/test_parameters.rb
tracksperanto-4.0.0 test/test_parameters.rb