Sha256: f0d2200917819fc6e3756cbd9bad439a42d5db6b668d6452f99d94a1b8cbb3ef

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

require File.expand_path("../test_helper", __FILE__)
require 'freighthopper/antonym_accessor'

class TestClass
  def private?() @private end
  def private=(p) @private = p end
end

class TwoArgumentForm < TestClass
  antonym_accessor :private, :public
end

class HashForm < TestClass
  antonym_accessor :private => :public
end

class AntonymAccessorTest < Test::Unit::TestCase
  def self.should_act_like_antonym_accessor
    should 'define a public= method' do
      @instance.public = true
      assert_not @instance.private?
    end

    should 'define a public? method' do
      @instance.private = false
      assert @instance.public?
    end
  end

  context 'two argument form' do
    setup {@instance = TwoArgumentForm.new}
    should_act_like_antonym_accessor
  end

  context 'hash form' do
    setup {@instance = HashForm.new}
    should_act_like_antonym_accessor
  end

  context 'anything else' do
    should 'raise' do
      begin
        TestClass.antonym_accessor :foo
      rescue => e
       assert e.message =~ /antonym_accessor expects/
      ensure
        assert_not_nil e
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
freighthopper-0.1.14 test/antonym_accessor_test.rb
freighthopper-0.1.13 test/antonym_accessor_test.rb
freighthopper-0.1.12 test/antonym_accessor_test.rb
freighthopper-0.1.11 test/antonym_accessor_test.rb