Sha256: a07e3f59fcba8358e51e5b8873c3a1fa274762a8f8a75821376a127b8593600a

Contents?: true

Size: 737 Bytes

Versions: 11

Compression:

Stored size: 737 Bytes

Contents

require_relative 'helper'


class TestSetter < Test::Unit::TestCase

  class Temp

    include Xot::Setter

    attr_accessor :x, :y

  end# Temp

  def temp(*args)
    Temp.new
  end

  def test_set()
    o = temp
    assert_equal nil, o.x
    o.set :x, 1
    assert_equal 1,   o.x
  end

  def test_set_by_hash()
    o = temp
    o.set x: 1, y: 2
    assert_equal [1, 2], [o.x, o.y]
  end

  def test_set_by_kwargs()
    o = temp
    o.set(**{x: 1, y: 2})
    assert_equal [1, 2], [o.x, o.y]
  end

  def test_invalid_name()
    assert_raise(NoMethodError) {temp.set :badname, 1}
    assert_raise(ArgumentError) {temp.set :badname}
  end

  def test_invalid_value()
    assert_raise(ArgumentError) {temp.set :x}
  end

end# TestSetter

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
xot-0.3 test/test_setter.rb
xot-0.2.1 test/test_setter.rb
xot-0.2 test/test_setter.rb
xot-0.1.42 test/test_setter.rb
xot-0.1.41 test/test_setter.rb
xot-0.1.40 test/test_setter.rb
xot-0.1.39 test/test_setter.rb
xot-0.1.38 test/test_setter.rb
xot-0.1.37 test/test_setter.rb
xot-0.1.36 test/test_setter.rb
xot-0.1.35 test/test_setter.rb