davidlee-state-fu 0.0.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/README.textile +13 -1
  2. data/lib/state-fu.rb +4 -3
  3. data/lib/state_fu/active_support_lite/array/access.rb +53 -0
  4. data/lib/state_fu/active_support_lite/array/conversions.rb +196 -0
  5. data/lib/state_fu/active_support_lite/array/extract_options.rb +20 -0
  6. data/lib/state_fu/active_support_lite/array/grouping.rb +106 -0
  7. data/lib/state_fu/active_support_lite/array/random_access.rb +12 -0
  8. data/lib/state_fu/active_support_lite/array/wrapper.rb +24 -0
  9. data/lib/state_fu/active_support_lite/array.rb +7 -0
  10. data/lib/state_fu/active_support_lite/blank.rb +58 -0
  11. data/lib/state_fu/active_support_lite/cattr_reader.rb +54 -0
  12. data/lib/state_fu/active_support_lite/inheritable_attributes.rb +1 -0
  13. data/lib/state_fu/active_support_lite/keys.rb +52 -0
  14. data/lib/state_fu/active_support_lite/object.rb +6 -0
  15. data/lib/state_fu/active_support_lite/string.rb +33 -0
  16. data/lib/state_fu/active_support_lite/symbol.rb +15 -0
  17. data/lib/state_fu/binding.rb +113 -58
  18. data/lib/state_fu/core_ext.rb +12 -13
  19. data/lib/state_fu/event.rb +4 -4
  20. data/lib/state_fu/exceptions.rb +12 -0
  21. data/lib/state_fu/helper.rb +74 -12
  22. data/lib/state_fu/lathe.rb +15 -0
  23. data/lib/state_fu/machine.rb +17 -25
  24. data/lib/state_fu/mock_transition.rb +38 -0
  25. data/lib/state_fu/persistence/active_record.rb +2 -2
  26. data/lib/state_fu/persistence/attribute.rb +4 -4
  27. data/lib/state_fu/persistence/base.rb +1 -1
  28. data/lib/state_fu/sprocket.rb +4 -0
  29. data/lib/state_fu/state.rb +4 -4
  30. data/lib/state_fu/transition.rb +24 -22
  31. data/spec/helper.rb +5 -3
  32. data/spec/integration/binding_extension_spec.rb +41 -0
  33. data/spec/integration/dynamic_requirement_spec.rb +160 -0
  34. data/spec/integration/example_01_document_spec.rb +2 -1
  35. data/spec/integration/lathe_extension_spec.rb +67 -0
  36. data/spec/integration/requirement_reflection_spec.rb +71 -11
  37. data/spec/integration/temp_spec.rb +17 -0
  38. data/spec/integration/transition_spec.rb +31 -19
  39. data/spec/units/binding_spec.rb +6 -0
  40. data/spec/units/event_spec.rb +6 -5
  41. data/spec/units/lathe_spec.rb +4 -2
  42. metadata +40 -17
@@ -734,7 +734,7 @@ describe StateFu::Transition do
734
734
  end
735
735
 
736
736
  it "should contain :go in @binding.valid_events if @binding.evaluate_requirement( :ok? ) is true" do
737
- mock( @binding ).evaluate_requirement( :ok? ) { true }
737
+ mock( @binding ).evaluate_requirement_with_args( :ok? ) { true }
738
738
  @binding.current_state.should == @machine.initial_state
739
739
  @binding.events.should == @machine.events
740
740
  @binding.valid_events.should == [@event]
@@ -867,19 +867,22 @@ describe StateFu::Transition do
867
867
 
868
868
  describe "a method defined on the stateful object" do
869
869
 
870
- it "should have self as the object itself" do
871
- called = false
872
- obj = @obj
873
- Klass.class_eval do
874
- define_method( :run_exec ) do |t|
875
- raise "self is #{self} not #{@obj}" unless self == obj
876
- called = true
877
- end
878
- end
879
- called.should == false
880
- trans = @obj.state_fu.fire!(:run)
881
- called.should == true
882
- end
870
+ # it "should have self as the object itself" do
871
+ # called = false
872
+ # Klass.class_eval do
873
+ # @@obj = nil
874
+ # cattr_accessor :obj
875
+ #
876
+ # def run_exec( t )
877
+ # called = true
878
+ # raise "self is #{self} not #{@@obj}" unless self == @@obj
879
+ # end
880
+ # end
881
+ # Klass.obj = @obj
882
+ # called.should == false
883
+ # trans = @obj.state_fu.fire!(:run)
884
+ # called.should == true
885
+ # end
883
886
 
884
887
  it "should receive a transition and be able to access the binding, etc through it" do
885
888
  mock( @obj ).run_exec(is_a(StateFu::Transition)) do |t|
@@ -943,20 +946,20 @@ describe StateFu::Transition do
943
946
 
944
947
  describe "a block passed to binding.transition" do
945
948
  it "should execute in the context of the transition initializer after it's set up" do
946
- Klass.class_eval do
947
- def run_exec( a ); raise "!"; end
948
- end
949
+ Klass.send :define_method, :run_exec, &lambda {|a| raise "!" }
950
+
949
951
  mock( @obj ).run_exec(is_a(StateFu::Transition)) do |t|
950
952
  t.args.should == ['who','yo','daddy?']
951
953
  t.options.should == {:hi => :mum}
952
954
  end
953
955
  set_method_arity( @obj, :run_exec, 1)
954
-
955
956
  trans = @obj.state_fu.transition( :run ) do
956
957
  @args = %w/ who yo daddy? /
957
958
  @options = {:hi => :mum}
958
959
  end
959
- trans.fire!
960
+ @obj.method(:run_exec).should be_kind_of(Proc)
961
+ @obj.method(:run_exec).arity.should == 1
962
+ trans.fire!()
960
963
  end
961
964
  end
962
965
 
@@ -1058,3 +1061,12 @@ describe StateFu::Transition do
1058
1061
  end
1059
1062
  end
1060
1063
  end
1064
+
1065
+ describe "sanity" do
1066
+ include MySpecHelper
1067
+ it "should be sane" do
1068
+ x = Object.new
1069
+ set_method_arity(x, :to_s, 2 )
1070
+ x.method( :to_s ).arity.should == 2
1071
+ end
1072
+ end
@@ -94,6 +94,12 @@ describe StateFu::Binding do
94
94
  @binding = @object.state_fu()
95
95
  end
96
96
 
97
+ describe "==" do
98
+ it "should be == :new" do
99
+ @binding.should == :new
100
+ end
101
+ end
102
+
97
103
  describe ".state() / initial state" do
98
104
  it "should default to machine.initial_state when no initial_state is explicitly defined" do
99
105
  @machine.initial_state.name.should == :new
@@ -8,6 +8,7 @@ describe StateFu::Event do
8
8
  include MySpecHelper
9
9
  before do
10
10
  @machine = Object.new
11
+ stub(@machine).tools() { [].extend( StateFu::ToolArray ) }
11
12
  end
12
13
 
13
14
  describe "Instance methods" do
@@ -51,23 +52,23 @@ describe StateFu::Event do
51
52
  end
52
53
 
53
54
  it "should set @origin to the result" do
54
- mock( @machine ).find_or_create_states_by_name( :initial ) { :result }
55
+ mock( @machine ).find_or_create_states_by_name( :initial ) { [:result] }
55
56
  @event.origins= :initial
56
- @event.origins.should == :result
57
+ @event.origins.should == [:result]
57
58
  end
58
59
 
59
60
  end
60
61
 
61
62
  describe 'targets=' do
62
63
  it "should call get_states_list_by_name with its argument" do
63
- mock( @machine ).find_or_create_states_by_name( :initial ) { }
64
+ mock( @machine ).find_or_create_states_by_name( :initial ) { [] }
64
65
  @event.targets= :initial
65
66
  end
66
67
 
67
68
  it "should set @target to the result" do
68
- mock( @machine ).find_or_create_states_by_name( :initial ) { :result }
69
+ mock( @machine ).find_or_create_states_by_name( :initial ) { [:result] }
69
70
  @event.targets= :initial
70
- @event.targets.should == :result
71
+ @event.targets.should == [:result]
71
72
  end
72
73
  end
73
74
 
@@ -10,6 +10,7 @@ describe StateFu::Lathe do
10
10
  @state = Object.new()
11
11
  @event = Object.new()
12
12
 
13
+ stub(@machine).tools() { [].extend( StateFu::ToolArray ) }
13
14
  @lathe = StateFu::Lathe.new( @machine )
14
15
  @states = [].extend StateFu::StateArray
15
16
  stub( @machine ).states() { @states }
@@ -469,7 +470,7 @@ describe StateFu::Lathe do
469
470
  end
470
471
 
471
472
  end
472
- end
473
+ end # a child lathe for a state
473
474
 
474
475
  describe "a child lathe for an event" do
475
476
  before do
@@ -563,5 +564,6 @@ describe StateFu::Lathe do
563
564
 
564
565
  end # requires
565
566
 
566
- end # ?
567
+ end # a child lathe for an event
568
+
567
569
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: davidlee-state-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Lee
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-05 00:00:00 -07:00
12
+ date: 2009-06-05 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,6 +26,20 @@ files:
26
26
  - Rakefile
27
27
  - lib/no_stdout.rb
28
28
  - lib/state-fu.rb
29
+ - lib/state_fu/active_support_lite/array.rb
30
+ - lib/state_fu/active_support_lite/array/access.rb
31
+ - lib/state_fu/active_support_lite/array/conversions.rb
32
+ - lib/state_fu/active_support_lite/array/extract_options.rb
33
+ - lib/state_fu/active_support_lite/array/grouping.rb
34
+ - lib/state_fu/active_support_lite/array/random_access.rb
35
+ - lib/state_fu/active_support_lite/array/wrapper.rb
36
+ - lib/state_fu/active_support_lite/blank.rb
37
+ - lib/state_fu/active_support_lite/cattr_reader.rb
38
+ - lib/state_fu/active_support_lite/inheritable_attributes.rb
39
+ - lib/state_fu/active_support_lite/keys.rb
40
+ - lib/state_fu/active_support_lite/object.rb
41
+ - lib/state_fu/active_support_lite/string.rb
42
+ - lib/state_fu/active_support_lite/symbol.rb
29
43
  - lib/state_fu/binding.rb
30
44
  - lib/state_fu/core_ext.rb
31
45
  - lib/state_fu/event.rb
@@ -38,6 +52,7 @@ files:
38
52
  - lib/state_fu/logger.rb
39
53
  - lib/state_fu/machine.rb
40
54
  - lib/state_fu/method_factory.rb
55
+ - lib/state_fu/mock_transition.rb
41
56
  - lib/state_fu/persistence.rb
42
57
  - lib/state_fu/persistence/active_record.rb
43
58
  - lib/state_fu/persistence/attribute.rb
@@ -48,16 +63,20 @@ files:
48
63
  - lib/state_fu/transition.rb
49
64
  - spec/helper.rb
50
65
  - spec/integration/active_record_persistence_spec.rb
66
+ - spec/integration/binding_extension_spec.rb
51
67
  - spec/integration/class_accessor_spec.rb
68
+ - spec/integration/dynamic_requirement_spec.rb
52
69
  - spec/integration/event_definition_spec.rb
53
70
  - spec/integration/ex_machine_for_accounts_spec.rb
54
71
  - spec/integration/example_01_document_spec.rb
55
72
  - spec/integration/example_02_string_spec.rb
56
73
  - spec/integration/instance_accessor_spec.rb
74
+ - spec/integration/lathe_extension_spec.rb
57
75
  - spec/integration/machine_duplication_spec.rb
58
76
  - spec/integration/requirement_reflection_spec.rb
59
77
  - spec/integration/sanity_spec.rb
60
78
  - spec/integration/state_definition_spec.rb
79
+ - spec/integration/temp_spec.rb
61
80
  - spec/integration/transition_spec.rb
62
81
  - spec/spec.opts
63
82
  - spec/units/binding_spec.rb
@@ -71,7 +90,7 @@ files:
71
90
  - spec/units/state_spec.rb
72
91
  - LICENSE
73
92
  - README.textile
74
- has_rdoc: true
93
+ has_rdoc: false
75
94
  homepage: http://github.com/davidlee/state-fu
76
95
  post_install_message:
77
96
  rdoc_options:
@@ -95,28 +114,32 @@ requirements: []
95
114
  rubyforge_project: state-fu
96
115
  rubygems_version: 1.2.0
97
116
  signing_key:
98
- specification_version: 2
117
+ specification_version: 3
99
118
  summary: A rich library for state-oriented programming with state machines / workflows
100
119
  test_files:
101
120
  - spec/units/machine_spec.rb
102
- - spec/units/method_factory_spec.rb
103
- - spec/units/lathe_spec.rb
104
121
  - spec/units/sprocket_spec.rb
105
- - spec/units/exceptions_spec.rb
106
122
  - spec/units/event_spec.rb
107
- - spec/units/fu_space_spec.rb
123
+ - spec/units/lathe_spec.rb
108
124
  - spec/units/binding_spec.rb
109
125
  - spec/units/state_spec.rb
110
- - spec/integration/example_02_string_spec.rb
111
- - spec/integration/state_definition_spec.rb
112
- - spec/integration/active_record_persistence_spec.rb
126
+ - spec/units/method_factory_spec.rb
127
+ - spec/units/exceptions_spec.rb
128
+ - spec/units/fu_space_spec.rb
129
+ - spec/helper.rb
130
+ - spec/integration/example_01_document_spec.rb
113
131
  - spec/integration/transition_spec.rb
114
- - spec/integration/machine_duplication_spec.rb
115
- - spec/integration/sanity_spec.rb
116
132
  - spec/integration/class_accessor_spec.rb
117
- - spec/integration/ex_machine_for_accounts_spec.rb
118
133
  - spec/integration/instance_accessor_spec.rb
119
- - spec/integration/event_definition_spec.rb
120
- - spec/integration/example_01_document_spec.rb
121
134
  - spec/integration/requirement_reflection_spec.rb
122
- - spec/helper.rb
135
+ - spec/integration/binding_extension_spec.rb
136
+ - spec/integration/lathe_extension_spec.rb
137
+ - spec/integration/machine_duplication_spec.rb
138
+ - spec/integration/state_definition_spec.rb
139
+ - spec/integration/event_definition_spec.rb
140
+ - spec/integration/sanity_spec.rb
141
+ - spec/integration/active_record_persistence_spec.rb
142
+ - spec/integration/example_02_string_spec.rb
143
+ - spec/integration/dynamic_requirement_spec.rb
144
+ - spec/integration/ex_machine_for_accounts_spec.rb
145
+ - spec/integration/temp_spec.rb