coulda 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  coulda*.gem
2
2
  coverage/*
3
+ .devver/devver_opts.yml
data/HISTORY CHANGED
@@ -15,3 +15,9 @@ Cleanup
15
15
  - Fixed issue 1 which prevented "extract method" on calls to Given/When/Then
16
16
  - Refactored Feature and Scenario accordingly assigning more responsibility to Feature
17
17
  - No longer enforcing order/presence of Given/When/Then within Scenarios
18
+
19
+ 0.3.0
20
+ -----
21
+ - Adds coulda:print_features task, providing plain text output in a
22
+ form similar to Cucumber's Gherkin
23
+ - Added hooks for Devver's continuous integration API
data/Rakefile CHANGED
@@ -4,6 +4,8 @@ require 'rake/testtask'
4
4
  require 'rake/rdoctask'
5
5
  require 'rake/gempackagetask'
6
6
 
7
+ require 'lib/coulda/tasks'
8
+
7
9
  gem 'thoughtbot-shoulda'
8
10
  require 'shoulda'
9
11
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/coulda.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{coulda}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
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{2009-09-12}
12
+ s.date = %q{2009-09-23}
13
13
  s.description = %q{Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse}
14
14
  s.email = %q{evan@tiggerpalace.com}
15
15
  s.extra_rdoc_files = [
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
- ".gitignore",
20
+ ".gitignore",
21
21
  "HISTORY",
22
22
  "LICENSE",
23
23
  "README.rdoc",
@@ -25,20 +25,26 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "coulda.gemspec",
27
27
  "example/sample.rb",
28
+ "geminstaller.yml",
28
29
  "lib/coulda.rb",
29
30
  "lib/coulda/feature.rb",
30
31
  "lib/coulda/scenario.rb",
32
+ "lib/coulda/tasks.rb",
31
33
  "test/feature_test.rb",
34
+ "test/integration/using_coulda_test.rb",
35
+ "test/regression/issue_1_test.rb",
32
36
  "test/scenario_test.rb",
33
37
  "test/test_helper.rb"
34
38
  ]
35
39
  s.homepage = %q{http://evan.tiggerpalace.com/}
36
40
  s.rdoc_options = ["--charset=UTF-8"]
37
41
  s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.3.4}
42
+ s.rubygems_version = %q{1.3.5}
39
43
  s.summary = %q{Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse}
40
44
  s.test_files = [
41
45
  "test/feature_test.rb",
46
+ "test/integration/using_coulda_test.rb",
47
+ "test/regression/issue_1_test.rb",
42
48
  "test/scenario_test.rb",
43
49
  "test/test_helper.rb"
44
50
  ]
data/geminstaller.yml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ #install required gems for coulda
3
+ defaults:
4
+ install_options: --include-dependencies --no-ri --no-rdoc
5
+ gems:
6
+ - name: bones
7
+ version: 2.1.1
8
+ - name: git
9
+ version: 1.2.1
10
+ - name: jeremymcanally-pending
11
+ install_options: --source http://gems.github.com
12
+ - name: thoughtbot-shoulda
13
+ install_options: --source http://gems.github.com
14
+ - name: technicalpickles-jeweler
15
+ install_options: --source http://gems.github.com
data/lib/coulda.rb CHANGED
@@ -19,3 +19,49 @@ module Kernel
19
19
  f
20
20
  end
21
21
  end
22
+
23
+ # Slightly tweeked version of #constantize from ActiveSupport 2.3.3
24
+ class String
25
+ # Ruby 1.9 introduces an inherit argument for Module#const_get and
26
+ # #const_defined? and changes their default behavior.
27
+ if Module.method(:const_get).arity == 1
28
+ # Tries to find a constant with the name specified in the argument string:
29
+ #
30
+ # "Module".constantize # => Module
31
+ # "Test::Unit".constantize # => Test::Unit
32
+ #
33
+ # The name is assumed to be the one of a top-level constant, no matter whether
34
+ # it starts with "::" or not. No lexical context is taken into account:
35
+ #
36
+ # C = 'outside'
37
+ # module M
38
+ # C = 'inside'
39
+ # C # => 'inside'
40
+ # "C".constantize # => 'outside', same as ::C
41
+ # end
42
+ #
43
+ # NameError is raised when the name is not in CamelCase or the constant is
44
+ # unknown.
45
+ def constantize
46
+ names = self.split('::')
47
+ names.shift if names.empty? || names.first.empty?
48
+
49
+ constant = Object
50
+ names.each do |name|
51
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
52
+ end
53
+ constant
54
+ end
55
+ else
56
+ def constantize #:nodoc:
57
+ names = self.split('::')
58
+ names.shift if names.empty? || names.first.empty?
59
+
60
+ constant = Object
61
+ names.each do |name|
62
+ constant = constant.const_get(name, false) || constant.const_missing(name)
63
+ end
64
+ constant
65
+ end
66
+ end
67
+ end
@@ -1,25 +1,38 @@
1
1
  module Coulda
2
2
  class Feature < Test::Unit::TestCase
3
3
  class << self
4
- def in_order_to(what)
5
- @in_order_to = what
6
- end
4
+ attr_accessor :description
5
+ attr_reader :in_order_to, :as_a, :i_want_to
7
6
 
8
- def as_a(who)
9
- @as_a = who
7
+ def include(*args)
8
+ super *args
9
+ extend *args
10
10
  end
11
11
 
12
- def i_want_to(what)
13
- @i_want_to = what
12
+ [:in_order_to, :as_a, :i_want_to].each do |field|
13
+ eval <<-HERE
14
+ def #{field}(arg = nil)
15
+ if arg
16
+ @#{field} = arg
17
+ else
18
+ @#{field}
19
+ end
20
+ end
21
+ HERE
14
22
  end
15
23
 
16
24
  def for_name(name)
17
25
  klass = Class.new(Feature)
18
- class_name = "Feature" + name.split(/\s/).map { |w| w.capitalize }.join
26
+ klass.description = name
27
+ class_name = feature_name_from(name)
19
28
  Object.const_set(class_name, klass)
20
29
  klass
21
30
  end
22
31
 
32
+ def feature_name_from(name)
33
+ "Feature" + name.split(/\s|_/).map { |w| w.capitalize }.join
34
+ end
35
+
23
36
  def assert_description
24
37
  if @in_order_to || @as_a || @i_want_to
25
38
  raise SyntaxError.new("Must call in_order_to if as_a and/or i_wanted_to called") unless @in_order_to
@@ -56,14 +69,26 @@ module Coulda
56
69
 
57
70
  def create_scenario_for(name, &test_implementation)
58
71
  @scenarios ||= []
72
+ scenario = nil
59
73
  if block_given?
60
74
  scenario = Scenario.new(name, &test_implementation)
75
+ scenario.statements = extract_statements_from &test_implementation
61
76
  else
62
77
  scenario = Scenario.new(name)
63
78
  end
64
79
  @scenarios << scenario
65
80
  scenario
66
81
  end
82
+
83
+ def extract_statements_from(&test_implementation)
84
+ @statements ||= []
85
+ @extracting_metadata = true
86
+ self.instance_eval(&test_implementation)
87
+ statements = @statements
88
+ @extracting_metadata = false
89
+ @statements = []
90
+ statements
91
+ end
67
92
  end
68
93
 
69
94
  # Scenario-less features should be pending
@@ -72,13 +97,18 @@ module Coulda
72
97
  end
73
98
  end
74
99
 
100
+ Statement = Struct.new(:type, :name, :block)
101
+
75
102
  %w[Given When Then].each do |statement|
76
103
  eval <<-HERE
77
104
  def #{statement}(name, &block)
78
- block.call if block_given?
105
+ if @extracting_metadata
106
+ @pending = true unless block_given?
107
+ @statements << stmt = Statement.new(:#{statement}, name, block)
108
+ else
109
+ yield if block_given?
110
+ end
79
111
  end
80
112
  HERE
81
113
  end
82
114
  end
83
-
84
-
@@ -1,8 +1,7 @@
1
1
  module Coulda
2
2
  class Scenario
3
3
  attr_reader :name
4
-
5
- Statement = Struct.new(:type, :name, :block)
4
+ attr_accessor :statements
6
5
 
7
6
  def initialize(name, &block)
8
7
  @name = name.to_s
@@ -11,14 +10,6 @@ module Coulda
11
10
  @pending = !block_given?
12
11
  end
13
12
 
14
- %w[Given When Then].each do |statement|
15
- eval <<-HERE
16
- def #{statement}(name, &block)
17
- @statements << stmt = Statement.new(:#{statement}, name, block)
18
- end
19
- HERE
20
- end
21
-
22
13
  def pending?
23
14
  @pending
24
15
  end
@@ -0,0 +1,3 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'tasks', '*.rake')].each do |f|
2
+ load f
3
+ end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), "..", "test_helper")
2
+
3
+ Feature "Using Coulda" do
4
+ in_order_to "perform lightweight integration/acceptance testing with Coulda"
5
+ as_a "developer"
6
+ i_want_to "have typical Coulda usage work"
7
+
8
+ def prove_methods_from_then_invokes_method_on_feature
9
+ # this was invoked
10
+ assert true
11
+ end
12
+
13
+ Scenario "A pending scenario with a Given/When/Then without a block" do
14
+ Given "this scenario"
15
+ When "an event happens" do; end
16
+ Then "should not error/fail because it is pending" do; end
17
+ end
18
+
19
+ Scenario "A scenario without a When" do
20
+ Given "this scenario" do; end
21
+ Then "should pass" do
22
+ prove_methods_from_then_invokes_method_on_feature
23
+ end
24
+ end
25
+
26
+ Scenario "that is live" do
27
+ Given "no prerequisites" do; end
28
+ When "no events" do; end
29
+ Then "should pass" do; end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__), "..", "test_helper")
2
+
3
+ module GivenSomething
4
+ def given_something
5
+ Given "something" do; end
6
+ end
7
+ end
8
+
9
+ # http://github.com/elight/coulda/issues#issue/1
10
+ class Issue1Test < Test::Unit::TestCase
11
+ context "A Feature that has a Scenario that invokes a 'Given/When/Then' called from a method" do
12
+ setup do
13
+ pendings_are_errors
14
+
15
+ @feature_without_errors = Feature "Issue 1 feature" do
16
+ include GivenSomething
17
+
18
+ in_order_to "foo"
19
+ as_a "bar"
20
+ i_want_to "blech"
21
+
22
+ Scenario "my scenario" do
23
+ given_something
24
+ When "the when" do; end
25
+ Then "the then" do; end
26
+ end
27
+ end
28
+ end
29
+
30
+ should "pass" do
31
+ assert(run_feature(@feature_without_errors))
32
+ end
33
+ end
34
+ end
35
+
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan David Light
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-12 00:00:00 -04:00
12
+ date: 2009-09-23 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,10 +40,14 @@ files:
40
40
  - VERSION
41
41
  - coulda.gemspec
42
42
  - example/sample.rb
43
+ - geminstaller.yml
43
44
  - lib/coulda.rb
44
45
  - lib/coulda/feature.rb
45
46
  - lib/coulda/scenario.rb
47
+ - lib/coulda/tasks.rb
46
48
  - test/feature_test.rb
49
+ - test/integration/using_coulda_test.rb
50
+ - test/regression/issue_1_test.rb
47
51
  - test/scenario_test.rb
48
52
  - test/test_helper.rb
49
53
  has_rdoc: true
@@ -76,5 +80,7 @@ specification_version: 3
76
80
  summary: Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse
77
81
  test_files:
78
82
  - test/feature_test.rb
83
+ - test/integration/using_coulda_test.rb
84
+ - test/regression/issue_1_test.rb
79
85
  - test/scenario_test.rb
80
86
  - test/test_helper.rb