coulda 0.6.3 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/HISTORY +4 -0
- data/README.rdoc +1 -1
- data/Rakefile +3 -0
- data/coulda-0.6.3.gem +0 -0
- data/coulda.gemspec +6 -4
- data/lib/coulda.rb +46 -27
- data/lib/coulda/pending.rb +1 -28
- data/lib/coulda/world.rb +2 -2
- data/lib/tasks/print_features.rake +23 -16
- data/test/feature_test.rb +3 -81
- data/test/test_helper.rb +1 -1
- metadata +38 -46
- data/lib/coulda/feature.rb +0 -65
- data/lib/coulda/scenario.rb +0 -66
- data/test/scenario_test.rb +0 -22
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/HISTORY
CHANGED
@@ -104,3 +104,7 @@ Cleanup
|
|
104
104
|
-----
|
105
105
|
- Renamed #pending to #coulda_pending to avoid conflicts with Rails 3
|
106
106
|
- Failing test in this release as I stupidly began working on some new features in the master branch. Don't use the new features (they're not documented outside of the new tests) and you'll be fine. ;-)
|
107
|
+
|
108
|
+
0.7.0
|
109
|
+
-----
|
110
|
+
- Significant refactoring using my branch of lispy (https://github.com/elight/lispy)
|
data/README.rdoc
CHANGED
@@ -57,4 +57,4 @@ Thanks to
|
|
57
57
|
---------
|
58
58
|
* David Chelimsky and Jim Weirich for turning me into the test-obsessed developer that I am.
|
59
59
|
* Timothy King for putting up with my scotch-powered rambling while working on v0.4.0
|
60
|
-
* We Are Titans (http://www.wearetitans.net/) for sponsoring v0.4.0
|
60
|
+
* We Are Titans (http://www.wearetitans.net/) for sponsoring v0.4.0 through 0.5.5
|
data/Rakefile
CHANGED
data/coulda-0.6.3.gem
ADDED
Binary file
|
data/coulda.gemspec
CHANGED
@@ -5,16 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{coulda}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Evan David Light"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-08-08}
|
13
13
|
s.description = %q{Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse}
|
14
|
-
s.email = %q{evan@
|
14
|
+
s.email = %q{evan@tripledogdare.net}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = Dir.glob('lib/**/*.rb') + Dir.glob('*') + Dir.glob('lib/tasks/**/*.rake')
|
20
20
|
s.homepage = %q{http://coulda.tiggerpalace.com}
|
@@ -24,6 +24,8 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.summary = %q{Test::Unit-based acceptance testing DSL}
|
25
25
|
s.test_files = Dir.glob('test/**')
|
26
26
|
|
27
|
+
s.add_dependency('yourdsl', '~> 0.7')
|
28
|
+
|
27
29
|
if s.respond_to? :specification_version then
|
28
30
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
29
31
|
s.specification_version = 3
|
data/lib/coulda.rb
CHANGED
@@ -1,40 +1,32 @@
|
|
1
1
|
require 'test/unit'
|
2
|
+
require 'yourdsl'
|
2
3
|
|
3
4
|
require File.join(File.dirname(__FILE__), 'coulda', 'world')
|
4
|
-
require File.join(File.dirname(__FILE__), 'coulda', 'feature')
|
5
|
-
require File.join(File.dirname(__FILE__), 'coulda', 'scenario')
|
6
5
|
require File.join(File.dirname(__FILE__), 'coulda', 'pending')
|
7
6
|
require File.join(File.dirname(__FILE__), 'coulda', 'vendor', 'constantize')
|
8
7
|
require File.join(File.dirname(__FILE__), 'coulda', 'vendor', 'underscore')
|
9
8
|
require File.join(File.dirname(__FILE__), 'coulda', 'tasks')
|
10
9
|
|
11
10
|
module Coulda
|
12
|
-
|
11
|
+
PROC_KEYWORDS = [:Given, :When, :Then, :And]
|
12
|
+
KEYWORDS = [:Scenario, :Tag, :in_order_to, :as_a, :i_want_to] + PROC_KEYWORDS
|
13
13
|
|
14
|
-
|
15
|
-
@feature_tags ||= []
|
16
|
-
@feature_tags << name.to_s
|
17
|
-
end
|
14
|
+
SyntaxError = Class.new(StandardError)
|
18
15
|
|
19
16
|
# Factory method for Test::Unit::TestCase subclasses
|
20
17
|
def Feature(name, opts = {}, &block)
|
21
|
-
|
18
|
+
test_class = Class.new(opts[:testcase_class] || Coulda.default_testcase_class || Test::Unit::TestCase)
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
20
|
+
assign_class_to_const test_class, name
|
21
|
+
test_class.instance_eval do
|
22
|
+
extend YourDSL
|
23
|
+
record_your_dsl :only => Coulda::KEYWORDS, :retain_blocks_for => Coulda::PROC_KEYWORDS
|
28
24
|
end
|
29
|
-
|
25
|
+
test_class.instance_eval &block if block_given?
|
30
26
|
|
31
|
-
|
32
|
-
World.register_feature(test_class, name)
|
33
|
-
|
34
|
-
Coulda::assign_class_to_const test_class, name
|
35
|
-
test_class.class_eval &block if block_given?
|
36
|
-
test_class.assert_presence_of_intent
|
27
|
+
World.register_feature(name, test_class.output)
|
37
28
|
|
29
|
+
generate_test_methods_from test_class
|
38
30
|
|
39
31
|
test_class
|
40
32
|
end
|
@@ -50,6 +42,8 @@ module Coulda
|
|
50
42
|
@class
|
51
43
|
end
|
52
44
|
|
45
|
+
private
|
46
|
+
|
53
47
|
def assign_class_to_const(test_class, potential_const)
|
54
48
|
base_name = potential_const
|
55
49
|
if potential_const !~ /^[a-zA-Z]/
|
@@ -59,15 +53,40 @@ module Coulda
|
|
59
53
|
Object.const_set(titleized_underscored_name, test_class)
|
60
54
|
end
|
61
55
|
|
62
|
-
def
|
63
|
-
unless
|
64
|
-
|
65
|
-
|
66
|
-
|
56
|
+
def generate_test_methods_from(test_class)
|
57
|
+
return unless test_class.output && test_class.output.expressions
|
58
|
+
|
59
|
+
test_class.output.expressions.each do |sexp|
|
60
|
+
next unless sexp.symbol == :Scenario
|
61
|
+
generate_test_method :for_scenario => sexp, :in_class => test_class
|
67
62
|
end
|
68
63
|
end
|
69
|
-
end
|
70
64
|
|
71
|
-
|
65
|
+
def generate_test_method(args = {})
|
66
|
+
scenario, test_class = args[:for_scenario], args[:in_class]
|
67
|
+
file_name = test_class.output.file
|
72
68
|
|
69
|
+
test_class.send(:define_method,"test_#{scenario.args.downcase.super_custom_underscore}") do
|
70
|
+
if scenario.scope.nil?
|
71
|
+
coulda_pending "Scenario '#{scenario.args}' in #{file_name}:#{scenario.lineno}"
|
72
|
+
else
|
73
|
+
execute_test_steps :for_scenario => scenario, :in_class => test_class
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def execute_test_steps(args = {})
|
79
|
+
scenario, test_class = args[:for_scenario], args[:in_class]
|
80
|
+
file_name = test_class.output.file
|
81
|
+
|
82
|
+
scenario.scope.expressions.each do |step_sexp|
|
83
|
+
if step_sexp.proc.nil?
|
84
|
+
coulda_pending "Scenario '#{scenario.args}': #{step_sexp.symbol} '#{step_sexp.args} in #{file_name}:#{step_sexp.lineno}"
|
85
|
+
else
|
86
|
+
instance_eval &step_sexp.proc
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
73
91
|
|
92
|
+
include ::Coulda
|
data/lib/coulda/pending.rb
CHANGED
@@ -2,9 +2,7 @@ module Test
|
|
2
2
|
module Unit
|
3
3
|
class TestCase
|
4
4
|
@@pending_cases = []
|
5
|
-
@@
|
6
|
-
@@pending_at_exit = false
|
7
|
-
@@exception_at_exit = false
|
5
|
+
@@at_exit = false
|
8
6
|
|
9
7
|
# Loosely based upon Jeremy McAnally's pending
|
10
8
|
|
@@ -21,31 +19,6 @@ module Test
|
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
24
|
-
|
25
|
-
def handle_exception(e, params = {})
|
26
|
-
stmt = params[:for_statement]
|
27
|
-
|
28
|
-
print "E"
|
29
|
-
@@error_contexts << params.merge(:exception => e)
|
30
|
-
|
31
|
-
@@exception_at_exit ||= begin
|
32
|
-
at_exit do
|
33
|
-
puts
|
34
|
-
puts "Exceptions"
|
35
|
-
puts "----------"
|
36
|
-
|
37
|
-
@@error_contexts.each_with_index do |ctx, i|
|
38
|
-
puts
|
39
|
-
puts "(#{i+1}) Feature: #{stmt[:scenario].feature.name}"
|
40
|
-
puts "Scenario: #{stmt[:scenario].name}"
|
41
|
-
puts "#{stmt[:type]} '#{stmt[:text]}'"
|
42
|
-
puts "In #{stmt[:file]} on line #{stmt[:line]}"
|
43
|
-
puts e.backtrace
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
22
|
end
|
50
23
|
end
|
51
24
|
end
|
data/lib/coulda/world.rb
CHANGED
@@ -9,32 +9,39 @@ namespace :coulda do
|
|
9
9
|
require 'test/unit'
|
10
10
|
|
11
11
|
# bug in test unit. Set to true to stop from running.
|
12
|
-
|
12
|
+
unless RUBY_VERSION =~ /^1.9/
|
13
|
+
Test::Unit.run = true
|
14
|
+
end
|
13
15
|
|
14
|
-
require 'coulda'
|
15
16
|
|
16
17
|
test_files = Dir.glob(File.join('test', '**', '*_test.rb'))
|
17
18
|
test_files.each do |file|
|
18
19
|
load file
|
19
20
|
end
|
20
21
|
|
21
|
-
Coulda::World.features.each do |
|
22
|
+
Coulda::World.features.each do |name, output|
|
22
23
|
puts "Feature: #{name}"
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
print "
|
34
|
-
|
24
|
+
output.expressions.each do |sexp|
|
25
|
+
case sexp.symbol
|
26
|
+
when :in_order_to
|
27
|
+
puts " In order to #{sexp.args}"
|
28
|
+
when :as_a
|
29
|
+
puts " As a #{sexp.args}"
|
30
|
+
when :i_want_to
|
31
|
+
puts " I want to #{sexp.args}"
|
32
|
+
when :Scenario
|
33
|
+
puts
|
34
|
+
print " "
|
35
|
+
print "(**PENDING**) " if sexp.scope.nil? || sexp.scope.expressions.any? { |step| step.proc.nil? }
|
36
|
+
puts "Scenario: #{sexp.args}"
|
37
|
+
sexp.scope.expressions.each do |step|
|
38
|
+
print " "
|
39
|
+
print "(**PENDING**) " unless step.proc
|
40
|
+
puts "#{step.symbol} #{step.args}"
|
41
|
+
end
|
42
|
+
puts
|
35
43
|
end
|
36
44
|
end
|
37
|
-
puts
|
38
45
|
end
|
39
46
|
end
|
40
47
|
end
|
data/test/feature_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class FeatureTest < Test::Unit::TestCase
|
4
|
-
|
5
4
|
should "be able to specify a default TestCase class to subclass for all Features" do
|
6
5
|
MyTestCase = Class.new(Test::Unit::TestCase)
|
7
6
|
Coulda.default_testcase_class = MyTestCase
|
@@ -25,7 +24,7 @@ class FeatureTest < Test::Unit::TestCase
|
|
25
24
|
@@counter = 1
|
26
25
|
setup do
|
27
26
|
@feature = Feature "foobarblech#{@@counter}" do
|
28
|
-
Scenario "" do
|
27
|
+
Scenario "ohai" do
|
29
28
|
Given "" do; end
|
30
29
|
Then "" do; end
|
31
30
|
end
|
@@ -37,55 +36,8 @@ class FeatureTest < Test::Unit::TestCase
|
|
37
36
|
assert @feature.ancestors.include? Test::Unit::TestCase
|
38
37
|
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
assert(@feature.respond_to?(condition))
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "that calls in_order_to, as_a, and i_want_to" do
|
47
|
-
should "not raise syntax error" do
|
48
|
-
assert_nothing_raised do
|
49
|
-
Feature "one" do
|
50
|
-
in_order_to "foo"
|
51
|
-
as_a "bar"
|
52
|
-
i_want_to "blech"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "that calls as_a and i_want_to" do
|
59
|
-
should "raise syntax error because in_order_to was not called once" do
|
60
|
-
assert_raise Coulda::SyntaxError do
|
61
|
-
Feature "two" do
|
62
|
-
as_a "bar"
|
63
|
-
i_want_to "blech"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "that calls in_order_to and i_want_to" do
|
70
|
-
should "raise syntax error because as_a was not called once" do
|
71
|
-
assert_raise Coulda::SyntaxError do
|
72
|
-
Feature "three" do
|
73
|
-
in_order_to "foo"
|
74
|
-
i_want_to "blech"
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "that calls in_order_to and as_a" do
|
81
|
-
should "raise syntax error because i_want_to was not called once" do
|
82
|
-
assert_raise Coulda::SyntaxError do
|
83
|
-
Feature "four" do
|
84
|
-
in_order_to "foo"
|
85
|
-
as_a "bar"
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
39
|
+
should "have a method test_ohai" do
|
40
|
+
assert @feature.instance_methods.include? :test_ohai
|
89
41
|
end
|
90
42
|
|
91
43
|
context "without scenarios" do
|
@@ -101,35 +53,5 @@ class FeatureTest < Test::Unit::TestCase
|
|
101
53
|
assert @feature_without_scenarios.instance_methods.grep(/^test_/).empty?
|
102
54
|
end
|
103
55
|
end
|
104
|
-
|
105
|
-
context "that does not have any errors" do
|
106
|
-
setup do
|
107
|
-
@feature_without_errors = Feature @@counter.to_s do
|
108
|
-
in_order_to "foo"
|
109
|
-
as_a "bar"
|
110
|
-
i_want_to "blech"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
### Integration tests
|
115
|
-
|
116
|
-
context "with a block containing a scenario" do
|
117
|
-
should "create a Feature instance method named 'test_<underscored_feature_name>_<underscored_scenario_name>'" do
|
118
|
-
@feature_without_errors.Scenario("pending scenario") {}
|
119
|
-
test_name = "test_pending_scenario"
|
120
|
-
test_name = test_name.to_sym if RUBY_VERSION =~ /^1.9/
|
121
|
-
assert(@feature_without_errors.instance_methods.include?(test_name), "Test is missing test method from scenario")
|
122
|
-
end
|
123
|
-
|
124
|
-
should "create a Scenario" do
|
125
|
-
@feature_without_errors.Scenario "pending scenario"
|
126
|
-
end
|
127
|
-
|
128
|
-
should "include the created Scenario in the return value of the 'scenarios' method" do
|
129
|
-
scenario = @feature_without_errors.Scenario "pending scenario"
|
130
|
-
assert(@feature_without_errors.scenarios.include?(scenario), "feature.scenarios doesn't contain the expected Scenario object")
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
56
|
end
|
135
57
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,42 +1,44 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: coulda
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 3
|
10
|
-
version: 0.6.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.1
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Evan David Light
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2010-12-23 00:00:00 -05:00
|
12
|
+
date: 2011-08-08 00:00:00.000000000 -04:00
|
19
13
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: yourdsl
|
17
|
+
requirement: &2153558420 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.7'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2153558420
|
26
|
+
description: Behaviour Driven Development derived from Cucumber but as an internal
|
27
|
+
DSL with methods for reuse
|
28
|
+
email: evan@tripledogdare.net
|
24
29
|
executables: []
|
25
|
-
|
26
30
|
extensions: []
|
27
|
-
|
28
|
-
extra_rdoc_files:
|
31
|
+
extra_rdoc_files:
|
29
32
|
- LICENSE
|
30
33
|
- README.rdoc
|
31
|
-
files:
|
32
|
-
- lib/coulda/feature.rb
|
34
|
+
files:
|
33
35
|
- lib/coulda/pending.rb
|
34
|
-
- lib/coulda/scenario.rb
|
35
36
|
- lib/coulda/tasks.rb
|
36
37
|
- lib/coulda/vendor/constantize.rb
|
37
38
|
- lib/coulda/vendor/underscore.rb
|
38
39
|
- lib/coulda/world.rb
|
39
40
|
- lib/coulda.rb
|
41
|
+
- coulda-0.6.3.gem
|
40
42
|
- coulda.gemspec
|
41
43
|
- Gemfile
|
42
44
|
- Gemfile.lock
|
@@ -48,43 +50,33 @@ files:
|
|
48
50
|
- lib/tasks/print_features.rake
|
49
51
|
- lib/tasks/tagged_tests.rake
|
50
52
|
- test/feature_test.rb
|
51
|
-
- test/scenario_test.rb
|
52
53
|
- test/test_helper.rb
|
53
54
|
has_rdoc: true
|
54
55
|
homepage: http://coulda.tiggerpalace.com
|
55
56
|
licenses: []
|
56
|
-
|
57
57
|
post_install_message:
|
58
|
-
rdoc_options:
|
58
|
+
rdoc_options:
|
59
59
|
- --charset=UTF-8
|
60
|
-
require_paths:
|
60
|
+
require_paths:
|
61
61
|
- lib
|
62
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
|
68
|
-
|
69
|
-
- 0
|
70
|
-
version: "0"
|
71
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
69
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
version: "0"
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
80
74
|
requirements: []
|
81
|
-
|
82
75
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.
|
76
|
+
rubygems_version: 1.6.2
|
84
77
|
signing_key:
|
85
78
|
specification_version: 3
|
86
79
|
summary: Test::Unit-based acceptance testing DSL
|
87
|
-
test_files:
|
80
|
+
test_files:
|
88
81
|
- test/feature_test.rb
|
89
|
-
- test/scenario_test.rb
|
90
82
|
- test/test_helper.rb
|
data/lib/coulda/feature.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
module Test
|
2
|
-
module Unit
|
3
|
-
class TestCase
|
4
|
-
include Coulda
|
5
|
-
|
6
|
-
def self.scenarios
|
7
|
-
@scenarios ||= []
|
8
|
-
@scenarios
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.current_scenario=(scenario)
|
12
|
-
@current_scenario = scenario
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.current_scenario
|
16
|
-
@current_scenario
|
17
|
-
end
|
18
|
-
|
19
|
-
%w[in_order_to as_a i_want_to].each do |intent|
|
20
|
-
eval <<-HERE
|
21
|
-
# An intent specifier
|
22
|
-
def self.#{intent}(val = nil)
|
23
|
-
val ? @#{intent} = val : @#{intent}
|
24
|
-
end
|
25
|
-
HERE
|
26
|
-
end
|
27
|
-
|
28
|
-
%w[Given When Then And].each do |stmt|
|
29
|
-
eval <<-HERE
|
30
|
-
# Specifies a prereqisite, event, or expectation. May be used in any order within the spec
|
31
|
-
def self.#{stmt}(text, &block)
|
32
|
-
step = nil
|
33
|
-
if block_given?
|
34
|
-
step = block
|
35
|
-
end
|
36
|
-
caller[0] =~ (/(.*):(.*)(:in)?/)
|
37
|
-
stmt = { :type => :#{stmt}, :text => text, :block => step, :file => $1, :line => $2, :scenario => current_scenario }
|
38
|
-
if text.is_a? Symbol
|
39
|
-
stmt[:method] = text
|
40
|
-
end
|
41
|
-
current_scenario.statements << stmt
|
42
|
-
end
|
43
|
-
HERE
|
44
|
-
end
|
45
|
-
|
46
|
-
def Tag(name)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Creates a Scenario instance and adds it to the Feature
|
50
|
-
def self.Scenario(scenario_name, &block)
|
51
|
-
@scenarios ||=[]
|
52
|
-
@scenarios << scenario = Scenario.new(scenario_name, self, &block)
|
53
|
-
scenario
|
54
|
-
end
|
55
|
-
|
56
|
-
# Raises an error if only some of the intent is captured (i.e., in_order_to and as_a without i_want_to)
|
57
|
-
def self.assert_presence_of_intent
|
58
|
-
presence = %w[in_order_to as_a i_want_to].map { |intent| instance_variable_get("@#{intent}") }
|
59
|
-
if presence.any? { |p| p } && !presence.all? { |p| p }
|
60
|
-
raise SyntaxError.new("Must have all or none of in_order, as_a, and i_want_to called in a Feature")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/lib/coulda/scenario.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
module Coulda
|
2
|
-
# A factory for Test::Unit::TestCase test methods
|
3
|
-
class Scenario
|
4
|
-
attr_reader :name, :test_class
|
5
|
-
attr_accessor :statements
|
6
|
-
|
7
|
-
def initialize(name, my_feature, &block)
|
8
|
-
raise Exception.new("Scenario must have a name") unless name
|
9
|
-
@name = name
|
10
|
-
@statements = []
|
11
|
-
@my_feature = my_feature
|
12
|
-
create_and_provision_test_method_using &block
|
13
|
-
end
|
14
|
-
|
15
|
-
# Predicate indicating if the Scenario was provided with an example
|
16
|
-
def pending?
|
17
|
-
statements.empty? || has_pending_statements?
|
18
|
-
end
|
19
|
-
|
20
|
-
def feature
|
21
|
-
@my_feature
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def create_and_provision_test_method_using(&block)
|
27
|
-
collect_scenario_statements_from &block
|
28
|
-
define_test_method_using do
|
29
|
-
scenario = self.class.current_scenario
|
30
|
-
scenario.statements.each do |stmt|
|
31
|
-
if stmt[:method]
|
32
|
-
if stmt[:block]
|
33
|
-
raise Exception.new "Passing a block to a method called-by-name is currently unhandle"
|
34
|
-
else
|
35
|
-
self.class.__send__(stmt[:method])
|
36
|
-
end
|
37
|
-
elsif stmt[:block]
|
38
|
-
self.instance_eval &(stmt[:block])
|
39
|
-
else
|
40
|
-
coulda_pending "#{stmt[:file]}:#{stmt[:line]}: Scenario '#{scenario.name}': #{stmt[:type]} '#{stmt[:text]}'"
|
41
|
-
break
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def collect_scenario_statements_from(&block)
|
48
|
-
@my_feature.current_scenario = self
|
49
|
-
if block_given?
|
50
|
-
@my_feature.instance_eval &block
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def define_test_method_using(&block)
|
55
|
-
scenario = self
|
56
|
-
@my_feature.send(:define_method, "test_#{@name.downcase.super_custom_underscore}") do
|
57
|
-
self.class.current_scenario = scenario
|
58
|
-
self.instance_eval &block if block
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def has_pending_statements?
|
63
|
-
statements.find { |s| s[:block].nil? && s[:method].nil? }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/test/scenario_test.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class ScenarioTest < Test::Unit::TestCase
|
4
|
-
context "A Scenario" do
|
5
|
-
setup do
|
6
|
-
@scenario = Scenario.new("foobar", Feature("something_or_other")) {}
|
7
|
-
end
|
8
|
-
|
9
|
-
context "when instantiated" do
|
10
|
-
context "with only a String" do
|
11
|
-
setup do
|
12
|
-
@scenario = Scenario.new("foobar", Feature("another"))
|
13
|
-
end
|
14
|
-
|
15
|
-
should "be pending" do
|
16
|
-
assert(@scenario.pending?)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|