elight-coulda 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +6 -0
- data/VERSION +1 -1
- data/coulda.gemspec +1 -1
- data/lib/coulda/feature.rb +26 -10
- data/lib/coulda/scenario.rb +1 -35
- data/test/feature_test.rb +1 -13
- data/test/scenario_test.rb +0 -111
- data/test/test_helper.rb +20 -0
- metadata +3 -2
data/HISTORY
CHANGED
@@ -9,3 +9,9 @@ Corrections for github gem build process
|
|
9
9
|
0.1.2 && 0.1.3
|
10
10
|
--------------
|
11
11
|
Cleanup
|
12
|
+
|
13
|
+
0.2.0
|
14
|
+
-----
|
15
|
+
- Fixed issue 1 which prevented "extract method" on calls to Given/When/Then
|
16
|
+
- Refactored Feature and Scenario accordingly assigning more responsibility to Feature
|
17
|
+
- No longer enforcing order/presence of Given/When/Then within Scenarios
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/coulda.gemspec
CHANGED
data/lib/coulda/feature.rb
CHANGED
@@ -30,15 +30,8 @@ module Coulda
|
|
30
30
|
|
31
31
|
def Scenario(name, &test_implementation)
|
32
32
|
raise SyntaxError.new("A scenario requires a name") unless name
|
33
|
-
|
34
|
-
|
35
|
-
@scenarios << scenario = Scenario.new(name, &test_implementation)
|
36
|
-
if scenario.pending?
|
37
|
-
define_method(method_name) { pending }
|
38
|
-
else
|
39
|
-
define_method(method_name, &test_implementation)
|
40
|
-
end
|
41
|
-
scenario
|
33
|
+
create_test_method_for(name, &test_implementation)
|
34
|
+
create_scenario_for(name, &test_implementation)
|
42
35
|
end
|
43
36
|
|
44
37
|
def scenarios
|
@@ -48,6 +41,29 @@ module Coulda
|
|
48
41
|
def pending?
|
49
42
|
@scenarios.all? { |s| !s.pending? }
|
50
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def create_test_method_for(name, &test_implementation)
|
48
|
+
method_name = "test_#{name.sub(/\s+/, "_").downcase}"
|
49
|
+
@scenarios ||= []
|
50
|
+
if block_given?
|
51
|
+
define_method(method_name, &test_implementation)
|
52
|
+
else
|
53
|
+
define_method(method_name) { pending }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_scenario_for(name, &test_implementation)
|
58
|
+
@scenarios ||= []
|
59
|
+
if block_given?
|
60
|
+
scenario = Scenario.new(name, &test_implementation)
|
61
|
+
else
|
62
|
+
scenario = Scenario.new(name)
|
63
|
+
end
|
64
|
+
@scenarios << scenario
|
65
|
+
scenario
|
66
|
+
end
|
51
67
|
end
|
52
68
|
|
53
69
|
# Scenario-less features should be pending
|
@@ -59,7 +75,7 @@ module Coulda
|
|
59
75
|
%w[Given When Then].each do |statement|
|
60
76
|
eval <<-HERE
|
61
77
|
def #{statement}(name, &block)
|
62
|
-
block.call
|
78
|
+
block.call if block_given?
|
63
79
|
end
|
64
80
|
HERE
|
65
81
|
end
|
data/lib/coulda/scenario.rb
CHANGED
@@ -8,8 +8,7 @@ module Coulda
|
|
8
8
|
@name = name.to_s
|
9
9
|
@block = block
|
10
10
|
@statements = []
|
11
|
-
|
12
|
-
@pending = @statements.empty? || @statements.any? { |s| s.block.nil? }
|
11
|
+
@pending = !block_given?
|
13
12
|
end
|
14
13
|
|
15
14
|
%w[Given When Then].each do |statement|
|
@@ -23,38 +22,5 @@ module Coulda
|
|
23
22
|
def pending?
|
24
23
|
@pending
|
25
24
|
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def check_statements
|
30
|
-
if @block
|
31
|
-
instance_eval &@block
|
32
|
-
assert_statements
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def assert_statements
|
37
|
-
if !pending? && @statements
|
38
|
-
assert_presence_of_statements
|
39
|
-
assert_order_of_statements
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def assert_presence_of_statements
|
44
|
-
givens_present = @statements.any? { |s| s.type == :Given }
|
45
|
-
raise SyntaxError.new("No Givens are present") unless givens_present
|
46
|
-
whens_present = @statements.any? { |s| s.type == :When }
|
47
|
-
raise SyntaxError.new("No Whens are present") unless whens_present
|
48
|
-
thens_present = @statements.any? { |s| s.type == :Then }
|
49
|
-
raise SyntaxError.new("No Thens are present") unless thens_present
|
50
|
-
end
|
51
|
-
|
52
|
-
def assert_order_of_statements
|
53
|
-
stmt_types = @statements.collect { |s| s.type }
|
54
|
-
unless stmt_types.rindex(:Given) < stmt_types.index(:When) &&
|
55
|
-
stmt_types.rindex(:When) < stmt_types.index(:Then)
|
56
|
-
raise SyntaxError.new("Given, Whens, Thens are out of order")
|
57
|
-
end
|
58
|
-
end
|
59
25
|
end
|
60
26
|
end
|
data/test/feature_test.rb
CHANGED
@@ -1,18 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "test_helper")
|
2
2
|
|
3
3
|
class FeatureTest < Test::Unit::TestCase
|
4
|
-
def run_feature(feature)
|
5
|
-
if Object::RUBY_VERSION =~ /^1.9/
|
6
|
-
result = MiniTest::Unit.autorun
|
7
|
-
else
|
8
|
-
# Assume 1.8.x
|
9
|
-
result = Test::Unit::TestResult.new
|
10
|
-
p = Proc.new {}
|
11
|
-
feature.suite.run(result, &p)
|
12
|
-
end
|
13
|
-
result
|
14
|
-
end
|
15
|
-
|
16
4
|
context "A Feature class" do
|
17
5
|
should "have Test::Unit::TestCase as an ancestor" do
|
18
6
|
assert(Feature.ancestors.include?(Test::Unit::TestCase))
|
@@ -85,7 +73,7 @@ class FeatureTest < Test::Unit::TestCase
|
|
85
73
|
|
86
74
|
should "not have any errors when run" do
|
87
75
|
result = run_feature @feature_without_scenarios
|
88
|
-
Object::RUBY_VERSION =~ /^1.9/ ?
|
76
|
+
Object::RUBY_VERSION =~ /^1.9/ ? assert(result) : assert(result.passed?)
|
89
77
|
end
|
90
78
|
end
|
91
79
|
|
data/test/scenario_test.rb
CHANGED
@@ -22,117 +22,6 @@ class ScenarioTest < Test::Unit::TestCase
|
|
22
22
|
assert(@scenario.pending?)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
|
-
context "with a block" do
|
27
|
-
context "when validating the semantics of the code in the block" do
|
28
|
-
should "raise a DSL syntax error if no givens are present" do
|
29
|
-
assert_raises Coulda::SyntaxError do
|
30
|
-
Scenario.new "foo" do
|
31
|
-
When "bar"
|
32
|
-
Then "blech"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
should "raise a DSL syntax error if no whens are present" do
|
38
|
-
assert_raises Coulda::SyntaxError do
|
39
|
-
Scenario.new "foo" do
|
40
|
-
Given "bar"
|
41
|
-
Then "blech"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
should "raise a DSL syntax error if no thens are present" do
|
47
|
-
assert_raises Coulda::SyntaxError do
|
48
|
-
Scenario.new "foo" do
|
49
|
-
Given "bar"
|
50
|
-
When "blech"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "and all givens occur before all whens" do
|
56
|
-
context "and all whens occur before all thens" do
|
57
|
-
should "not raise an error" do
|
58
|
-
assert_nothing_raised do
|
59
|
-
Scenario.new "foo" do
|
60
|
-
Given "bar"
|
61
|
-
When "blech"
|
62
|
-
Then "baz"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "and all whens do not occur before all thens" do
|
69
|
-
should "raise a DSL syntax error" do
|
70
|
-
assert_raises Coulda::SyntaxError do
|
71
|
-
Scenario.new "foo" do
|
72
|
-
Given "bar"
|
73
|
-
When "blech"
|
74
|
-
Then "baz"
|
75
|
-
When "foobarblech"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "where not all givens occur before all whens" do
|
83
|
-
context "and all whens occur before all thens" do
|
84
|
-
should "raise a DSL syntax error" do
|
85
|
-
assert_raises Coulda::SyntaxError do
|
86
|
-
Scenario.new "foo" do
|
87
|
-
Given "bar"
|
88
|
-
When "blech"
|
89
|
-
Given "foobarblech"
|
90
|
-
Then "baz"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "and all whens do not occur before all thens" do
|
97
|
-
should "raise a DSL syntax error" do
|
98
|
-
assert_raises Coulda::SyntaxError do
|
99
|
-
Scenario.new "foo" do
|
100
|
-
Given "bar"
|
101
|
-
When "blech"
|
102
|
-
Given "barblech"
|
103
|
-
Then "baz"
|
104
|
-
When "foobarblech"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "where givens, whens, are present and in the correct order" do
|
112
|
-
context "but a Given does not have a block" do
|
113
|
-
should "declare the scenario pending" do
|
114
|
-
scenario = Scenario.new "foo" do
|
115
|
-
Given "bar"
|
116
|
-
When "blech" do; end
|
117
|
-
Then "baz" do; end
|
118
|
-
end
|
119
|
-
assert(scenario.pending?)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context "and the givens, whens, and thens have blocks" do
|
124
|
-
should "not be pending" do
|
125
|
-
scenario = Scenario.new "foo" do
|
126
|
-
Given "bar" do; end
|
127
|
-
When "blech" do; end
|
128
|
-
Then "baz" do; end
|
129
|
-
end
|
130
|
-
assert(!scenario.pending?)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
25
|
end
|
137
26
|
end
|
138
27
|
end
|
data/test/test_helper.rb
CHANGED
@@ -6,3 +6,23 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
|
|
6
6
|
require 'coulda'
|
7
7
|
|
8
8
|
include Coulda
|
9
|
+
|
10
|
+
def run_feature(feature)
|
11
|
+
if Object::RUBY_VERSION =~ /^1.9/
|
12
|
+
result = MiniTest::Unit.autorun
|
13
|
+
else
|
14
|
+
# Assume 1.8.x
|
15
|
+
result = Test::Unit::TestResult.new
|
16
|
+
p = Proc.new {}
|
17
|
+
feature.suite.run(result, &p)
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
def pendings_are_errors
|
23
|
+
Feature.class_eval do
|
24
|
+
def pending
|
25
|
+
raise Exception.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elight-coulda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan David Light
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- test/test_helper.rb
|
49
49
|
has_rdoc: false
|
50
50
|
homepage: http://evan.tiggerpalace.com/
|
51
|
+
licenses:
|
51
52
|
post_install_message:
|
52
53
|
rdoc_options:
|
53
54
|
- --charset=UTF-8
|
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
69
|
requirements: []
|
69
70
|
|
70
71
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.3.5
|
72
73
|
signing_key:
|
73
74
|
specification_version: 3
|
74
75
|
summary: Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse
|