moody 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/moody.rb +1 -0
  2. data/moody.gemspec +1 -1
  3. data/test/test_moody.rb +15 -0
  4. metadata +2 -2
@@ -3,6 +3,7 @@ module Moody
3
3
  def self.extended(base)
4
4
  base.class_eval do
5
5
  attr_accessor :state
6
+ delegate_to_state :switch_to
6
7
  end
7
8
  end
8
9
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "moody"
3
- s.version = "0.2.0"
3
+ s.version = "0.2.1"
4
4
  s.date = "2010-10-23"
5
5
 
6
6
  s.description = "Simple and straightforward implementation of the state pattern, inspired by the StatePattern gem"
@@ -72,6 +72,15 @@ class TestMoodyByExample < Test::Unit::TestCase
72
72
  end
73
73
  end
74
74
 
75
+ class EmptyContext
76
+ class A < Moody::State; end
77
+ class B < Moody::State; end
78
+
79
+ extend Moody::Context
80
+
81
+ initial_state A
82
+ end
83
+
75
84
  def setup
76
85
  $callbacks = []
77
86
  @context_class = Class.new(SiegeTank)
@@ -92,6 +101,12 @@ class TestMoodyByExample < Test::Unit::TestCase
92
101
  assert test_context.state.is_a?(TankMode)
93
102
  end
94
103
 
104
+ def test_switch_from_context
105
+ test_context = EmptyContext.new
106
+ test_context.switch_to EmptyContext::B
107
+ assert test_context.state.is_a?(EmptyContext::B)
108
+ end
109
+
95
110
  def test_delegates_methods
96
111
  test_context = @context_class.new
97
112
  test_context.siege_mode!
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Nicol\xC3\xA1s Sanguinetti"