davidlee-state-fu 0.3.1 → 0.10.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.
- data/README.textile +124 -34
- data/Rakefile +36 -30
- data/lib/no_stdout.rb +1 -1
- data/lib/state-fu.rb +9 -8
- data/lib/state_fu/active_support_lite/array/access.rb +12 -5
- data/lib/state_fu/active_support_lite/array/conversions.rb +10 -4
- data/lib/state_fu/active_support_lite/array/extract_options.rb +5 -4
- data/lib/state_fu/active_support_lite/array/grouping.rb +7 -4
- data/lib/state_fu/active_support_lite/array/random_access.rb +4 -3
- data/lib/state_fu/active_support_lite/array/wrapper.rb +4 -3
- data/lib/state_fu/active_support_lite/array.rb +3 -1
- data/lib/state_fu/active_support_lite/blank.rb +18 -9
- data/lib/state_fu/active_support_lite/cattr_reader.rb +4 -1
- data/lib/state_fu/active_support_lite/keys.rb +8 -3
- data/lib/state_fu/active_support_lite/misc.rb +6 -4
- data/lib/state_fu/active_support_lite/module/delegation.rb +130 -0
- data/lib/state_fu/active_support_lite/module.rb +1 -0
- data/lib/state_fu/active_support_lite/object.rb +5 -2
- data/lib/state_fu/active_support_lite/string.rb +6 -1
- data/lib/state_fu/active_support_lite/symbol.rb +2 -1
- data/lib/state_fu/applicable.rb +41 -0
- data/lib/state_fu/{helper.rb → arrays.rb} +45 -121
- data/lib/state_fu/binding.rb +136 -159
- data/lib/state_fu/core_ext.rb +78 -10
- data/lib/state_fu/event.rb +112 -48
- data/lib/state_fu/exceptions.rb +80 -34
- data/lib/state_fu/executioner.rb +149 -0
- data/lib/state_fu/has_options.rb +16 -0
- data/lib/state_fu/hooks.rb +21 -16
- data/lib/state_fu/interface.rb +80 -83
- data/lib/state_fu/lathe.rb +361 -148
- data/lib/state_fu/logger.rb +122 -45
- data/lib/state_fu/machine.rb +60 -32
- data/lib/state_fu/method_factory.rb +180 -72
- data/lib/state_fu/methodical.rb +17 -0
- data/lib/state_fu/persistence/active_record.rb +6 -1
- data/lib/state_fu/persistence/attribute.rb +1 -0
- data/lib/state_fu/persistence/base.rb +8 -6
- data/lib/state_fu/persistence.rb +94 -23
- data/lib/state_fu/sprocket.rb +26 -11
- data/lib/state_fu/state.rb +8 -27
- data/lib/state_fu/transition.rb +207 -98
- data/lib/state_fu/transition_query.rb +214 -0
- data/lib/state_fu.rb +1 -0
- data/lib/tasks/spec_last.rake +46 -0
- data/lib/tasks/state_fu.rake +57 -0
- data/lib/vizier.rb +61 -61
- data/spec/custom_formatter.rb +49 -0
- data/spec/features/binding_and_transition_helper_mixin_spec.rb +2 -2
- data/spec/features/method_missing_only_once_spec.rb +28 -0
- data/spec/features/not_requirements_spec.rb +83 -46
- data/spec/features/plotter_spec.rb +97 -0
- data/spec/features/shared_log_spec.rb +7 -0
- data/spec/features/singleton_machine_spec.rb +39 -0
- data/spec/features/state_and_array_options_accessor_spec.rb +1 -1
- data/spec/features/{transition_boolean_comparison.rb → transition_boolean_comparison_spec.rb} +29 -18
- data/spec/helper.rb +6 -117
- data/spec/integration/active_record_persistence_spec.rb +18 -4
- data/spec/integration/binding_extension_spec.rb +1 -1
- data/spec/integration/class_accessor_spec.rb +49 -59
- data/spec/integration/event_definition_spec.rb +20 -20
- data/spec/integration/example_01_document_spec.rb +13 -8
- data/spec/integration/example_02_string_spec.rb +3 -2
- data/spec/integration/instance_accessor_spec.rb +16 -19
- data/spec/integration/lathe_extension_spec.rb +2 -2
- data/spec/integration/machine_duplication_spec.rb +59 -37
- data/spec/integration/relaxdb_persistence_spec.rb +6 -3
- data/spec/integration/requirement_reflection_spec.rb +66 -57
- data/spec/integration/state_definition_spec.rb +72 -66
- data/spec/integration/transition_spec.rb +169 -173
- data/spec/spec.opts +5 -3
- data/spec/spec_helper.rb +132 -0
- data/spec/state_fu_spec.rb +870 -0
- data/spec/units/binding_spec.rb +33 -22
- data/spec/units/event_spec.rb +3 -22
- data/spec/units/exceptions_spec.rb +7 -0
- data/spec/units/lathe_spec.rb +7 -7
- data/spec/units/machine_spec.rb +67 -75
- data/spec/units/method_factory_spec.rb +55 -48
- data/spec/units/sprocket_spec.rb +5 -7
- data/spec/units/state_spec.rb +33 -24
- metadata +31 -19
- data/lib/state_fu/active_support_lite/inheritable_attributes.rb +0 -1
- data/lib/state_fu/fu_space.rb +0 -51
- data/lib/state_fu/mock_transition.rb +0 -38
- data/spec/BDD/plotter_spec.rb +0 -115
- data/spec/integration/dynamic_requirement_spec.rb +0 -160
- data/spec/integration/ex_machine_for_accounts_spec.rb +0 -79
- data/spec/integration/sanity_spec.rb +0 -31
- data/spec/units/fu_space_spec.rb +0 -95
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
thisdir = File.expand_path(File.dirname(__FILE__))
|
|
3
|
+
|
|
4
|
+
# ensure we require state-fu from lib, not gems
|
|
5
|
+
$LOAD_PATH.unshift( "#{thisdir}/../lib" )
|
|
6
|
+
require 'state-fu'
|
|
7
|
+
require 'no_stdout'
|
|
8
|
+
require 'fileutils'
|
|
9
|
+
require 'rubygems'
|
|
10
|
+
require 'spec'
|
|
11
|
+
|
|
12
|
+
# record the log output on each run
|
|
13
|
+
LOGFILE = File.join('log', 'spec.log') unless Object.const_defined?('LOGFILE')
|
|
14
|
+
FileUtils.rm LOGFILE if File.exists?(LOGFILE)
|
|
15
|
+
StateFu::Logger.level = Logger::INFO
|
|
16
|
+
StateFu::Logger.logger = Logger.new(LOGFILE)
|
|
17
|
+
|
|
18
|
+
module MySpecHelper
|
|
19
|
+
include NoStdout
|
|
20
|
+
|
|
21
|
+
def prepare_active_record( options={}, &migration )
|
|
22
|
+
if skip_slow_specs?
|
|
23
|
+
skip_slow_specs and return false
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
begin
|
|
27
|
+
require 'activesupport'
|
|
28
|
+
require 'active_record'
|
|
29
|
+
require 'sqlite3'
|
|
30
|
+
rescue LoadError => e
|
|
31
|
+
pending "skipping specifications due to load error: #{e}"
|
|
32
|
+
return false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
options.symbolize_keys!
|
|
36
|
+
options.assert_valid_keys( :db_config, :migration_name, :hidden )
|
|
37
|
+
|
|
38
|
+
# connect ActiveRecord
|
|
39
|
+
db_config = options.delete(:db_config) || {
|
|
40
|
+
:adapter => 'sqlite3',
|
|
41
|
+
:database => ':memory:'
|
|
42
|
+
}
|
|
43
|
+
ActiveRecord::Base.establish_connection( db_config )
|
|
44
|
+
|
|
45
|
+
return unless block_given?
|
|
46
|
+
|
|
47
|
+
# prepare the migration
|
|
48
|
+
migration_class_name =
|
|
49
|
+
options.delete(:migration_name) || 'BeforeSpecMigration'
|
|
50
|
+
make_pristine_class( migration_class_name, ActiveRecord::Migration )
|
|
51
|
+
migration_class = migration_class_name.constantize
|
|
52
|
+
migration_class.class_eval( &migration )
|
|
53
|
+
|
|
54
|
+
# run the migration without spewing crap everywhere
|
|
55
|
+
if options.delete(:hidden) != false
|
|
56
|
+
no_stdout { migration_class.migrate( :up ) }
|
|
57
|
+
else
|
|
58
|
+
migration_class.migrate( :up )
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def skip_slow_specs?
|
|
63
|
+
!!ENV['SKIP_SLOW_SPECS']
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def skip_slow_specs
|
|
67
|
+
pending('Skipping slow specs - run $ rake all if you want them')
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def skip_unless_relaxdb
|
|
71
|
+
unless Object.const_defined?( 'RelaxDB' )
|
|
72
|
+
pending('Skipping specs because you do not have the relaxdb gem (paulcarey-relaxdb) installed ...')
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def prepare_relaxdb( options={} )
|
|
77
|
+
if skip_slow_specs?
|
|
78
|
+
return false
|
|
79
|
+
end
|
|
80
|
+
begin
|
|
81
|
+
require 'relaxdb'
|
|
82
|
+
if Object.const_defined?( "RelaxDB" )
|
|
83
|
+
RelaxDB.configure :host => "localhost", :port => 5984, :design_doc => "spec_doc"
|
|
84
|
+
RelaxDB.delete_db "relaxdb_spec" rescue "ok"
|
|
85
|
+
RelaxDB.use_db "relaxdb_spec"
|
|
86
|
+
RelaxDB.enable_view_creation
|
|
87
|
+
end
|
|
88
|
+
rescue LoadError => e
|
|
89
|
+
# pending "skipping specifications due to load error: #{e}"
|
|
90
|
+
return false
|
|
91
|
+
end
|
|
92
|
+
begin
|
|
93
|
+
RelaxDB.replicate_db "relaxdb_spec_base", "relaxdb_spec"
|
|
94
|
+
RelaxDB.enable_view_creation
|
|
95
|
+
rescue => e
|
|
96
|
+
puts "\n===== Run rake create_base_db before the first spec run ====="
|
|
97
|
+
puts
|
|
98
|
+
exit!
|
|
99
|
+
end
|
|
100
|
+
#
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def make_pristine_class(class_name, superklass=Object, &block)
|
|
104
|
+
@class_names ||= []
|
|
105
|
+
@class_names << class_name
|
|
106
|
+
klass = Class.new( superklass )
|
|
107
|
+
klass.send( :include, StateFu )
|
|
108
|
+
Object.send(:remove_const, class_name ) if Object.const_defined?( class_name )
|
|
109
|
+
Object.const_set(class_name, klass)
|
|
110
|
+
klass.class_eval &block if block_given?
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def reset!
|
|
114
|
+
@class_names ||= []
|
|
115
|
+
@class_names.each do |class_name|
|
|
116
|
+
Object.send(:remove_const, class_name ) if Object.const_defined?( class_name )
|
|
117
|
+
end
|
|
118
|
+
@class_names = []
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def set_method_arity( object, method_name, needed_arity = 1 )
|
|
122
|
+
raise caller.first.inspect
|
|
123
|
+
a = Proc.new {}
|
|
124
|
+
stub( a ).arity() { needed_arity }
|
|
125
|
+
stub( object ).method( anything ) { |x| object.send(x) }
|
|
126
|
+
stub( object ).method( method_name ) { a }
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
Spec::Runner.configure do |config|
|
|
131
|
+
config.include MySpecHelper
|
|
132
|
+
end
|