Exspec 1.0.1

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/lib/exspec.rb ADDED
@@ -0,0 +1,217 @@
1
+ require "active_support/core_ext"
2
+
3
+ require_relative "exspec/context_manager"
4
+ require_relative "exspec/executor"
5
+ require_relative "exspec/spec_manager"
6
+ require_relative "exspec/logger"
7
+ require_relative "exspec/spec_runner"
8
+ require_relative "exspec/reporter"
9
+ require_relative "exspec/regression_test_reporter"
10
+ require_relative "exspec/helpers"
11
+ require_relative "exspec/extensions/extension"
12
+ require_relative "exspec/extensions/mocking"
13
+ require_relative "exspec/extensions/rails"
14
+ parent_dirs do |parent_dir|
15
+ configured = false
16
+ ["exspec.rb", "config/exspec.rb", "exspec/config.rb", "exspec/exspec.rb"].each do |file|
17
+ file = File.expand_path file, parent_dir
18
+ require file and configured = true and break if File.file?(file)
19
+ end
20
+ break if configured
21
+ end
22
+
23
+ module Exspec
24
+ def self.config
25
+ config = {
26
+ :test_dir => "test/exspec",
27
+ :command_prefix => "!",
28
+ :comment_sign => "!# ",
29
+ :spec_separator => ".",
30
+ :spec_extension => ".rb",
31
+ :regression_test_reporter => RegressionTestReporter
32
+ }
33
+ Extension.config config
34
+ config
35
+ end
36
+
37
+ TEST_DIR = File.expand_path(config[:test_dir])
38
+ COMMAND_PREFIX = config[:command_prefix]
39
+ COMMENT_SIGN = config[:comment_sign]
40
+ SPEC_SEPARATOR = config[:spec_separator]
41
+ SPEC_EXTENSION = config[:spec_extension]
42
+ REGRESSION_TEST_REPORTER = config[:regression_test_reporter]
43
+
44
+ SkipSignal = Class.new(StandardError)
45
+
46
+ class Exspec
47
+ def initialize(components={})
48
+ Extension.initialize_exspec self, components
49
+ @context_manager = components[:context_manager] || ContextManager.new(self)
50
+ @executor = components[:executor] || Executor.new(self)
51
+ @spec_manager = components[:spec_manager] || SpecManager.new(self)
52
+ @logger = components[:logger] || Logger.new
53
+ @runner = components[:runner] || SpecRunner.new(self)
54
+ @reporter = components[:reporter] || Reporter.new
55
+ end
56
+
57
+ delegate :without_logging, :last_instruction, :erase_last_instruction, :log, :to => :@logger
58
+ delegate :eval, :raw_eval, :exspec_eval, :last_value, :last_value=, :last_exspec_value, :to => :@context_manager
59
+ delegate :spec, :specs, :current_spec, :to => :@spec_manager
60
+ delegate :spec_failed, :spec_succeeded, :puts, :print, :show_comment, :to => :@reporter
61
+ delegate :run, :run_specs, :run_stack, :to => :@runner
62
+
63
+ attr_reader :logger, :context_manager, :reporter, :spec_manager, :runner, :executor
64
+ alias_method :context, :context_manager
65
+
66
+ def module
67
+ ::Exspec
68
+ end
69
+
70
+ def execute(instruction)
71
+ executor.eval instruction do |callbacks|
72
+ callbacks.after do |command, params, value|
73
+ context.last_exspec_value = value
74
+ if command.nil?
75
+ commit instruction, value
76
+ end
77
+ if last_exspec_value != last_value || command == "_" || command == ""
78
+ puts "#{COMMAND_PREFIX}_: #{last_exspec_value.inspect}"
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def report_to(reporter=reporter)
85
+ reporter = reporter.new if reporter.is_a? Class
86
+ reporter_backup = @reporter
87
+ @reporter = reporter
88
+ if block_given?
89
+ begin
90
+ yield if block_given?
91
+ ensure
92
+ @reporter = reporter_backup if block_given?
93
+ end
94
+ end
95
+ end
96
+
97
+ def save(description, comment=nil)
98
+ comment(comment) unless comment.nil?
99
+ spec_manager.save logger, description
100
+ end
101
+
102
+ def load(description)
103
+ reset
104
+ spec = spec(description)
105
+ return nil if spec.nil?
106
+ without_logging { runner.run_stack spec }
107
+ spec_manager.current_spec = spec
108
+ end
109
+
110
+ def include(description)
111
+ spec = spec(description)
112
+ without_logging do
113
+ run spec
114
+ end
115
+ commit "#{COMMAND_PREFIX}include #{spec.name}"
116
+ end
117
+
118
+ def retry
119
+ instructions = logger.instructions
120
+ load current_spec
121
+ instructions.each do |instruction|
122
+ execute instruction rescue nil
123
+ end
124
+ last_value
125
+ end
126
+
127
+ def reset
128
+ context_manager.start_new_context
129
+ logger.clear
130
+ spec_manager.current_spec = nil
131
+ return_spec nil
132
+ end
133
+
134
+ def comment(text)
135
+ show_comment text
136
+ commit "#{COMMAND_PREFIX}comment #{text}", last_value
137
+ end
138
+
139
+ def redo
140
+ last = last_instruction
141
+ return nil if last.nil?
142
+ execute last
143
+ end
144
+
145
+ def assert(statement=nil, comment=nil)
146
+ val = without_logging { raw_eval statement }
147
+ if val
148
+ spec_succeeded "Successful: #{comment || statement}"
149
+ else
150
+ spec_failed "Failed: #{comment || statement}"
151
+ end
152
+ commit "#{COMMAND_PREFIX}assert #{statement.strip}" + (comment ? " #{COMMENT_SIGN}#{comment}" : "")
153
+ val
154
+ end
155
+
156
+ def expect(statement=nil, comment=nil)
157
+ return expect_inspect nil, comment if statement.nil?
158
+ actual = last_value
159
+ expect = without_logging { raw_eval statement }
160
+ if expect == actual
161
+ spec_succeeded "Successful: #{comment || "value is #{prepare_output(expect)}"}"
162
+ else
163
+ spec_failed "Failed: #{comment || "expected #{prepare_output(expect)}"}, but got #{prepare_output(actual)}"
164
+ end
165
+ commit "#{COMMAND_PREFIX}expect #{statement.strip}" + (comment ? " #{COMMENT_SIGN}#{comment}" : ""), expect
166
+ end
167
+
168
+ def expect_inspect(expect=nil, comment=nil)
169
+ actual = inspect_last_value
170
+ expect = actual if expect.nil?
171
+ successful = actual.to_s == expect.to_s
172
+ if successful
173
+ spec_succeeded "Successful: #{comment || "inspecting last value has yielded #{prepare_output(actual)}"}"
174
+ else
175
+ actual_pos = 0
176
+ successful = true
177
+ expect.each_char do |char|
178
+ successful = false
179
+ for actual_pos in actual_pos..actual.length
180
+ successful = (actual[actual_pos] == char)
181
+ break if successful
182
+ end
183
+ break if actual_pos == actual.length
184
+ end
185
+ spec_succeeded "Successful (fuzzy): #{comment || "inspecting last value has yielded #{prepare_output(actual)}"}" if successful
186
+ end
187
+ unless successful
188
+ spec_failed "Failed: #{comment || "expected inspecting last value to yield #{prepare_output(expect)}, but was #{prepare_output(actual)}"}"
189
+ end
190
+ commit "#{COMMAND_PREFIX}expect_inspect #{expect}" + (comment ? " #{COMMENT_SIGN}#{comment}" : "")
191
+ actual
192
+ end
193
+
194
+ def inspect_last_value
195
+ last_value.is_a?(String) ? last_value : last_value.inspect
196
+ end
197
+
198
+ def commit(instruction, value=last_value)
199
+ logger.log instruction, value
200
+ return_spec value
201
+ end
202
+
203
+ def return_spec(value)
204
+ self.last_value = value
205
+ end
206
+
207
+ def prepare_output(value)
208
+ return "nil" if value.nil?
209
+ return "\"#{value}\"" if value.is_a? String
210
+ value
211
+ end
212
+ end
213
+ end
214
+
215
+ require_relative "exspec/irb/irb_exspec"
216
+
217
+ Exspec::Extension.loaded
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Exspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Helge Holzmann
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Don't write specs anymore, just save 'em while testing your code interactively.
31
+ Specs will become a byproduct.
32
+ email: helgeho@invelop.de
33
+ executables:
34
+ - exspec
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - lib/exspec/context_manager.rb
39
+ - lib/exspec/execute_callbacks.rb
40
+ - lib/exspec/executor.rb
41
+ - lib/exspec/extensions/extension.rb
42
+ - lib/exspec/extensions/mocking.rb
43
+ - lib/exspec/extensions/rails.rb
44
+ - lib/exspec/helpers.rb
45
+ - lib/exspec/irb/irb_context_manager.rb
46
+ - lib/exspec/irb/irb_exspec.rb
47
+ - lib/exspec/irb/irb_patch.rb
48
+ - lib/exspec/logger.rb
49
+ - lib/exspec/regression_test_reporter.rb
50
+ - lib/exspec/reporter.rb
51
+ - lib/exspec/spec.rb
52
+ - lib/exspec/spec_manager.rb
53
+ - lib/exspec/spec_runner.rb
54
+ - lib/exspec.rb
55
+ - bin/exspec
56
+ homepage: https://github.com/helgeho/Exspec
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.25
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Exspec test framework
80
+ test_files: []