coulda 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  coulda*.gem
2
2
  coverage/*
3
3
  .devver/devver_opts.yml
4
+ .devver/*.log
data/HISTORY CHANGED
@@ -21,3 +21,9 @@ Cleanup
21
21
  - Adds coulda:print_features task, providing plain text output in a
22
22
  form similar to Cucumber's Gherkin
23
23
  - Added hooks for Devver's continuous integration API
24
+
25
+ 0.3.1
26
+ -----
27
+ - Minor refactorings
28
+ - Added more examples
29
+ - Adds "And" support to Given, When, and Then
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{coulda}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.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"]
@@ -14,7 +14,7 @@ require 'coulda/scenario'
14
14
  module Kernel
15
15
  def Feature(name, &block)
16
16
  f = Feature.for_name(name)
17
- f.class_eval(&block)
17
+ f.class_eval(&block) if block_given?
18
18
  f.assert_description
19
19
  f
20
20
  end
@@ -1,4 +1,17 @@
1
1
  module Coulda
2
+ Statement = Struct.new(:type, :name, :block)
3
+
4
+ module FeatureBehavior
5
+ %w[Given When Then And].each do |statement|
6
+ eval <<-HERE
7
+ def #{statement}(name, &block)
8
+ @pending = true unless block_given?
9
+ @statements << stmt = Statement.new(:#{statement}, name, block)
10
+ end
11
+ HERE
12
+ end
13
+ end
14
+
2
15
  class Feature < Test::Unit::TestCase
3
16
  class << self
4
17
  attr_accessor :description
@@ -23,6 +36,7 @@ module Coulda
23
36
 
24
37
  def for_name(name)
25
38
  klass = Class.new(Feature)
39
+ klass.extend(FeatureBehavior)
26
40
  klass.description = name
27
41
  class_name = feature_name_from(name)
28
42
  Object.const_set(class_name, klass)
@@ -82,10 +96,8 @@ module Coulda
82
96
 
83
97
  def extract_statements_from(&test_implementation)
84
98
  @statements ||= []
85
- @extracting_metadata = true
86
99
  self.instance_eval(&test_implementation)
87
100
  statements = @statements
88
- @extracting_metadata = false
89
101
  @statements = []
90
102
  statements
91
103
  end
@@ -95,20 +107,13 @@ module Coulda
95
107
  def default_test
96
108
  pending
97
109
  end
98
- end
99
-
100
- Statement = Struct.new(:type, :name, :block)
101
110
 
102
- %w[Given When Then].each do |statement|
103
- eval <<-HERE
104
- def #{statement}(name, &block)
105
- if @extracting_metadata
106
- @pending = true unless block_given?
107
- @statements << stmt = Statement.new(:#{statement}, name, block)
108
- else
111
+ %w[Given When Then And].each do |statement|
112
+ eval <<-HERE
113
+ def #{statement}(name, &block)
109
114
  yield if block_given?
110
115
  end
111
- end
112
- HERE
116
+ HERE
117
+ end
113
118
  end
114
119
  end
@@ -1,22 +1,44 @@
1
1
  require File.join(File.dirname(__FILE__), "test_helper")
2
2
 
3
3
  class FeatureTest < Test::Unit::TestCase
4
+ context "A Feature instance" do
5
+ @@counter = 1
6
+ setup do
7
+ feature_class = Feature.for_name "foobarblech#{@@counter}"
8
+ @@counter += 1
9
+ @feature = feature_class.new("default_test")
10
+ end
11
+
12
+ %w[Given When Then And].each do |condition|
13
+ should "have a method called '#{condition}'" do
14
+ assert(@feature.respond_to?(condition))
15
+ end
16
+ end
17
+ end
18
+
4
19
  context "A Feature class" do
5
20
  should "have Test::Unit::TestCase as an ancestor" do
6
21
  assert(Feature.ancestors.include?(Test::Unit::TestCase))
7
22
  end
8
23
 
9
24
  context "created by name" do
25
+ @@counter = 1
10
26
  setup do
11
- @feature = Feature.for_name "foo"
27
+ @feature = Feature.for_name "foo#{@@counter}"
28
+ @@counter += 1
12
29
  end
13
30
 
14
31
  should "be a subclass of Feature" do
15
32
  assert(@feature.ancestors.include?(Feature))
16
33
  end
34
+
35
+ %w[Given When Then And].each do |condition|
36
+ should "have a method called '#{condition}'" do
37
+ assert(@feature.respond_to?(condition), "does not have a method called #{condition}")
38
+ end
39
+ end
17
40
  end
18
41
 
19
-
20
42
  context "that calls in_order_to, as_a, and i_want_to" do
21
43
  should "not raise syntax error" do
22
44
  assert_nothing_raised do
@@ -6,7 +6,6 @@ Feature "Using Coulda" do
6
6
  i_want_to "have typical Coulda usage work"
7
7
 
8
8
  def prove_methods_from_then_invokes_method_on_feature
9
- # this was invoked
10
9
  assert true
11
10
  end
12
11
 
@@ -17,8 +16,8 @@ Feature "Using Coulda" do
17
16
  end
18
17
 
19
18
  Scenario "A scenario without a When" do
20
- Given "this scenario" do; end
21
- Then "should pass" do
19
+ Given "a scenario calling a Feature instance method" do; end
20
+ Then "should pass if the method does not fail/error" do
22
21
  prove_methods_from_then_invokes_method_on_feature
23
22
  end
24
23
  end
@@ -28,4 +27,13 @@ Feature "Using Coulda" do
28
27
  When "no events" do; end
29
28
  Then "should pass" do; end
30
29
  end
30
+
31
+ Scenario "A scenario with a lot of Ands" do
32
+ Given "no prerequisites" do; end
33
+ And "some more lack of prerequisites" do; end
34
+ When "something doesn't happen" do; end
35
+ And "something else doesn't happen" do; end
36
+ Then "something else" do; end
37
+ And "should pass" do; end
38
+ end
31
39
  end
@@ -6,12 +6,6 @@ class ScenarioTest < Test::Unit::TestCase
6
6
  @scenario = Scenario.new("foobar")
7
7
  end
8
8
 
9
- %w[Given When Then].each do |condition|
10
- should "have a method called '#{condition}'" do
11
- assert(@scenario.respond_to?(condition.to_sym))
12
- end
13
- end
14
-
15
9
  context "when instantiated" do
16
10
  context "with only a String" do
17
11
  setup do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coulda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan David Light