coulda 0.5.0 → 0.5.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/HISTORY +5 -0
- data/VERSION +1 -1
- data/coulda.gemspec +1 -1
- data/lib/coulda/feature.rb +6 -2
- data/lib/coulda/scenario.rb +18 -13
- data/test/integration/using_coulda_test.rb +12 -0
- data/test/regression/pending_scenarios_test.rb +3 -3
- metadata +1 -1
data/HISTORY
CHANGED
@@ -70,3 +70,8 @@ Cleanup
|
|
70
70
|
- Coulda::Features created from the Kernel::Feature method now create and return a subclass of Test::Unit::TestCase (or a subclass of the specified :testcase_class).
|
71
71
|
- The block passed to Kernel::Feature changes self to be the Test::Unit::TestCase subclass. That way, it's virtually identical to a "class Foo < Test::Unit::TestCase"
|
72
72
|
- Removed dependency on Jeremy McAnally's "pending" gem in favor of an implementation targetted specifically to Coulda's needs (File names and line numbers of the Given/When/Then/And that is unimplemented)
|
73
|
+
|
74
|
+
0.5.1
|
75
|
+
-----
|
76
|
+
- Adds support for call-by-name/symbol (i.e., "Given :some_method invokes the 'some_method' method")
|
77
|
+
- Mocked pending within test Scenarios so that the test suite passes instead of incorrectly reporting pending tests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/coulda.gemspec
CHANGED
data/lib/coulda/feature.rb
CHANGED
@@ -31,10 +31,14 @@ module Test
|
|
31
31
|
def self.#{stmt}(text, &block)
|
32
32
|
step = nil
|
33
33
|
if block_given?
|
34
|
-
|
34
|
+
step = block
|
35
35
|
end
|
36
36
|
caller[0] =~ (/(.*):(.*)(:in)?/)
|
37
|
-
|
37
|
+
stmt = { :type => :#{stmt}, :text => text, :block => step, :file => $1, :line => $2 }
|
38
|
+
if text.is_a? Symbol
|
39
|
+
stmt[:method] = text
|
40
|
+
end
|
41
|
+
current_scenario.statements << stmt
|
38
42
|
end
|
39
43
|
HERE
|
40
44
|
end
|
data/lib/coulda/scenario.rb
CHANGED
@@ -2,26 +2,19 @@ module Coulda
|
|
2
2
|
# A factory for Test::Unit::TestCase test methods
|
3
3
|
class Scenario
|
4
4
|
attr_reader :name, :test_class
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :statements
|
6
6
|
|
7
7
|
def initialize(name, my_feature, &block)
|
8
8
|
raise Exception.new("Scenario must have a name") unless name
|
9
9
|
@name = name
|
10
10
|
@statements = []
|
11
|
-
@steps = []
|
12
|
-
@pending = false
|
13
11
|
@my_feature = my_feature
|
14
|
-
|
15
|
-
create_and_provision_test_method_using &block
|
16
|
-
else
|
17
|
-
@pending = true
|
18
|
-
define_test_method_using { pending }
|
19
|
-
end
|
12
|
+
create_and_provision_test_method_using &block
|
20
13
|
end
|
21
14
|
|
22
15
|
# Predicate indicating if the Scenario was provided with an example
|
23
16
|
def pending?
|
24
|
-
|
17
|
+
statements.empty? || has_pending_statements?
|
25
18
|
end
|
26
19
|
|
27
20
|
private
|
@@ -30,7 +23,13 @@ module Coulda
|
|
30
23
|
collect_scenario_statements_from &block
|
31
24
|
define_test_method_using do
|
32
25
|
self.class.current_scenario.statements.each do |stmt|
|
33
|
-
if stmt[:
|
26
|
+
if stmt[:method]
|
27
|
+
if stmt[:block]
|
28
|
+
raise Exception.new "Passing a block to a method called-by-name is currently unhandle"
|
29
|
+
else
|
30
|
+
self.__send__(stmt[:method])
|
31
|
+
end
|
32
|
+
elsif stmt[:block]
|
34
33
|
self.instance_eval &(stmt[:block])
|
35
34
|
else
|
36
35
|
pending self.class.current_scenario, stmt
|
@@ -42,15 +41,21 @@ module Coulda
|
|
42
41
|
|
43
42
|
def collect_scenario_statements_from(&block)
|
44
43
|
@my_feature.current_scenario = self
|
45
|
-
|
44
|
+
if block_given?
|
45
|
+
@my_feature.instance_eval &block
|
46
|
+
end
|
46
47
|
end
|
47
48
|
|
48
49
|
def define_test_method_using(&block)
|
49
50
|
scenario = self
|
50
51
|
@my_feature.send(:define_method, "test_#{@name.downcase.super_custom_underscore}") do
|
51
52
|
self.class.current_scenario = scenario
|
52
|
-
self.instance_eval &block
|
53
|
+
self.instance_eval &block if block
|
53
54
|
end
|
54
55
|
end
|
56
|
+
|
57
|
+
def has_pending_statements?
|
58
|
+
statements.find { |s| s[:block].nil? && s[:method].nil? }
|
59
|
+
end
|
55
60
|
end
|
56
61
|
end
|
@@ -9,6 +9,8 @@ Feature "Using Coulda", :testcase_class => Test::Unit::TestCase do
|
|
9
9
|
as_a "developer"
|
10
10
|
i_want_to "have typical Coulda usage work"
|
11
11
|
|
12
|
+
def some_method; end
|
13
|
+
|
12
14
|
def prove_methods_from_then_invokes_method_on_feature
|
13
15
|
assert true
|
14
16
|
end
|
@@ -42,4 +44,14 @@ Feature "Using Coulda", :testcase_class => Test::Unit::TestCase do
|
|
42
44
|
Then "something else" do; end
|
43
45
|
And "should pass" do; end
|
44
46
|
end
|
47
|
+
|
48
|
+
Scenario "A scenario that invokes a method by name" do
|
49
|
+
Given "a method" do
|
50
|
+
mock(self).some_method
|
51
|
+
end
|
52
|
+
|
53
|
+
When :some_method
|
54
|
+
|
55
|
+
Then "'some_method' should have been called" do; end
|
56
|
+
end
|
45
57
|
end
|
@@ -13,11 +13,11 @@ class PendingScenariosTest < Test::Unit::TestCase
|
|
13
13
|
include RR::Adapters::TestUnit
|
14
14
|
|
15
15
|
@scenario = Scenario "my scenario" do
|
16
|
-
Given "
|
17
|
-
When "the when"
|
18
|
-
Then "the then" do
|
16
|
+
Given "this scenario that will call #pending because it has a pending step" do
|
19
17
|
mock(self).pending
|
20
18
|
end
|
19
|
+
When "I have this pending step"
|
20
|
+
Then "the test should pass anyway because I mocked pending"
|
21
21
|
end
|
22
22
|
@@counter += 1
|
23
23
|
end
|