coulda 0.2.0

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.
@@ -0,0 +1,2 @@
1
+ coulda*.gem
2
+ coverage/*
data/HISTORY ADDED
@@ -0,0 +1,17 @@
1
+ 0.1.0
2
+ -----
3
+ Initial release with basic features to generate tests from internal DSL
4
+
5
+ 0.1.1
6
+ -----
7
+ Corrections for github gem build process
8
+
9
+ 0.1.2 && 0.1.3
10
+ --------------
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/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ coulda
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2009, Evan David Light
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
24
+
@@ -0,0 +1,48 @@
1
+ coulda
2
+ ------
3
+ coulda gives you Cucumber-like BDD power but with an internal DSL. This means no "call-by-regexp" and
4
+ no Gherkin/plain-text/external DSL. coulda is just code -- but with a Cucumber-like take on BDD.
5
+
6
+ coulda, obviously was inspired by Cucumber, Shoulda, but also Thor. coulda believes that the best way to reuse
7
+ code is the good ol' fashioned method. Instead of sharing files of regexps mapped to procs, you just write
8
+ methods. That simple.
9
+
10
+ You can define the implementation of your Given/When/Then right there with the behavior description. Or,
11
+ if you want to reuse some Givens/Whens/Thens, just write a method! And if you find your Feature is getting
12
+ too bloated or that you would like to reuse Givens/Whens/Thens between features, put them in a helper.
13
+
14
+ Easy as pie.
15
+
16
+ require 'rubygems'
17
+ require 'coulda'
18
+ include Coulda
19
+
20
+ Feature "feature name" do
21
+ in_order_to "foo"
22
+ as_a "bar"
23
+ i_want_to "blech"
24
+
25
+ def something
26
+ end
27
+
28
+ def expectation
29
+ end
30
+
31
+ Scenario "pending scenario"
32
+
33
+ Scenario "another scenario" do
34
+ Given "a pending prereq"
35
+ When "something happens" do
36
+ something
37
+ end
38
+ Then "expect something else" do
39
+ expectation
40
+ end
41
+ end
42
+
43
+ Scenario "that is live" do
44
+ Given "foo" do; end
45
+ When "bar" do; end
46
+ Then "blech" do; end
47
+ end
48
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/gempackagetask'
6
+
7
+ gem 'thoughtbot-shoulda'
8
+ require 'shoulda'
9
+
10
+ # Test::Unit::UI::VERBOSE
11
+ test_files_pattern = 'test/**/*_test.rb'
12
+ src_files_pattern = 'src/**/*.rb'
13
+
14
+ Rake::TestTask.new do |t|
15
+ src_files = Dir[src_files_pattern]
16
+ src_files.each { |f| puts f; require f[0...-3] }
17
+ t.pattern = test_files_pattern
18
+ t.verbose = false
19
+ end
20
+
21
+ begin
22
+ require 'jeweler'
23
+ Jeweler::Tasks.new do |s|
24
+ s.name = "coulda"
25
+ s.version = "0.1.1"
26
+ s.authors = ["Evan David Light"]
27
+ s.email = "evan@tiggerpalace.com"
28
+ s.summary = "Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse"
29
+ s.homepage = "http://evan.tiggerpalace.com/"
30
+ s.description = "Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse"
31
+ end
32
+ rescue LoadError
33
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
34
+ end
35
+
36
+
37
+ desc 'Default: run tests.'
38
+ task :default => 'test'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{coulda}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Evan David Light"]
12
+ s.date = %q{2009-09-12}
13
+ s.description = %q{Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse}
14
+ s.email = %q{evan@tiggerpalace.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "HISTORY",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "coulda.gemspec",
27
+ "example/sample.rb",
28
+ "lib/coulda.rb",
29
+ "lib/coulda/feature.rb",
30
+ "lib/coulda/scenario.rb",
31
+ "test/feature_test.rb",
32
+ "test/scenario_test.rb",
33
+ "test/test_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://evan.tiggerpalace.com/}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.4}
39
+ s.summary = %q{Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse}
40
+ s.test_files = [
41
+ "test/feature_test.rb",
42
+ "test/scenario_test.rb",
43
+ "test/test_helper.rb"
44
+ ]
45
+ s.add_dependency 'jeremymcanally-pending', '>= 0.1'
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ else
53
+ end
54
+ else
55
+ end
56
+ end
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'coulda'
3
+ include Coulda
4
+
5
+ Feature "feature name" do
6
+ in_order_to "foo"
7
+ as_a "bar"
8
+ i_want_to "blech"
9
+
10
+ def something
11
+ end
12
+
13
+ def expectation
14
+ end
15
+
16
+ Scenario "pending scenario"
17
+
18
+ Scenario "another scenario" do
19
+ Given "a pending prereq"
20
+ When "something happens" do
21
+ something
22
+ end
23
+ Then "expect something else" do
24
+ expectation
25
+ end
26
+ end
27
+
28
+ Scenario "that is live" do
29
+ Given "foo" do; end
30
+ When "bar" do; end
31
+ Then "blech" do; end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module Coulda
2
+ SyntaxError = Class.new(StandardError)
3
+ end
4
+
5
+
6
+ require 'test/unit'
7
+
8
+ gem 'jeremymcanally-pending', '>= 0.1'
9
+ require 'pending'
10
+
11
+ require 'coulda/feature'
12
+ require 'coulda/scenario'
13
+
14
+ module Kernel
15
+ def Feature(name, &block)
16
+ f = Feature.for_name(name)
17
+ f.class_eval(&block)
18
+ f.assert_description
19
+ f
20
+ end
21
+ end
@@ -0,0 +1,84 @@
1
+ module Coulda
2
+ class Feature < Test::Unit::TestCase
3
+ class << self
4
+ def in_order_to(what)
5
+ @in_order_to = what
6
+ end
7
+
8
+ def as_a(who)
9
+ @as_a = who
10
+ end
11
+
12
+ def i_want_to(what)
13
+ @i_want_to = what
14
+ end
15
+
16
+ def for_name(name)
17
+ klass = Class.new(Feature)
18
+ class_name = "Feature" + name.split(/\s/).map { |w| w.capitalize }.join
19
+ Object.const_set(class_name, klass)
20
+ klass
21
+ end
22
+
23
+ def assert_description
24
+ if @in_order_to || @as_a || @i_want_to
25
+ raise SyntaxError.new("Must call in_order_to if as_a and/or i_wanted_to called") unless @in_order_to
26
+ raise SyntaxError.new("Must call as_a if in_order_to and/or i_want_to called") unless @as_a
27
+ raise SyntaxError.new("Must call i_want_to if in_order_to and/or as_a called") unless @i_want_to
28
+ end
29
+ end
30
+
31
+ def Scenario(name, &test_implementation)
32
+ raise SyntaxError.new("A scenario requires a name") unless name
33
+ create_test_method_for(name, &test_implementation)
34
+ create_scenario_for(name, &test_implementation)
35
+ end
36
+
37
+ def scenarios
38
+ @scenarios ||= []
39
+ end
40
+
41
+ def pending?
42
+ @scenarios.all? { |s| !s.pending? }
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
67
+ end
68
+
69
+ # Scenario-less features should be pending
70
+ def default_test
71
+ pending
72
+ end
73
+ end
74
+
75
+ %w[Given When Then].each do |statement|
76
+ eval <<-HERE
77
+ def #{statement}(name, &block)
78
+ block.call if block_given?
79
+ end
80
+ HERE
81
+ end
82
+ end
83
+
84
+
@@ -0,0 +1,26 @@
1
+ module Coulda
2
+ class Scenario
3
+ attr_reader :name
4
+
5
+ Statement = Struct.new(:type, :name, :block)
6
+
7
+ def initialize(name, &block)
8
+ @name = name.to_s
9
+ @block = block
10
+ @statements = []
11
+ @pending = !block_given?
12
+ end
13
+
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
+ def pending?
23
+ @pending
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,112 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class FeatureTest < Test::Unit::TestCase
4
+ context "A Feature class" do
5
+ should "have Test::Unit::TestCase as an ancestor" do
6
+ assert(Feature.ancestors.include?(Test::Unit::TestCase))
7
+ end
8
+
9
+ context "created by name" do
10
+ setup do
11
+ @feature = Feature.for_name "foo"
12
+ end
13
+
14
+ should "be a subclass of Feature" do
15
+ assert(@feature.ancestors.include?(Feature))
16
+ end
17
+ end
18
+
19
+
20
+ context "that calls in_order_to, as_a, and i_want_to" do
21
+ should "not raise syntax error" do
22
+ assert_nothing_raised do
23
+ Feature "one" do
24
+ in_order_to "foo"
25
+ as_a "bar"
26
+ i_want_to "blech"
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ context "that calls as_a and i_want_to" do
33
+ should "raise syntax error because in_order_to was not called once" do
34
+ assert_raise Coulda::SyntaxError do
35
+ Feature "two" do
36
+ as_a "bar"
37
+ i_want_to "blech"
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ context "that calls in_order_to and i_want_to" do
44
+ should "raise syntax error because as_a was not called once" do
45
+ assert_raise Coulda::SyntaxError do
46
+ Feature "three" do
47
+ in_order_to "foo"
48
+ i_want_to "blech"
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ context "that calls in_order_to and as_a" do
55
+ should "raise syntax error because i_want_to was not called once" do
56
+ assert_raise Coulda::SyntaxError do
57
+ Feature "four" do
58
+ in_order_to "foo"
59
+ as_a "bar"
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ context "without scenarios" do
66
+ setup do
67
+ @feature_without_scenarios = Feature "five" do
68
+ in_order_to "foo"
69
+ as_a "bar"
70
+ i_want_to "blech"
71
+ end
72
+ end
73
+
74
+ should "not have any errors when run" do
75
+ result = run_feature @feature_without_scenarios
76
+ Object::RUBY_VERSION =~ /^1.9/ ? assert(result) : assert(result.passed?)
77
+ end
78
+ end
79
+
80
+ context "that does not have any errors" do
81
+ @@counter = 1
82
+ setup do
83
+ @feature_without_errors = Feature @@counter.to_s do
84
+ in_order_to "foo"
85
+ as_a "bar"
86
+ i_want_to "blech"
87
+ end
88
+ @@counter += 1
89
+ end
90
+
91
+ ### Integration tests
92
+
93
+ context "with a block containing a scenario" do
94
+ should "create a Feature instance method named 'test_<underscored_scenario_name>'" do
95
+ @feature_without_errors.Scenario "pending scenario"
96
+ test_name = "test_pending_scenario"
97
+ test_name = :test_pending_scenario if RUBY_VERSION =~ /^1.9/
98
+ assert(@feature_without_errors.instance_methods.include?(test_name), "Feature is missing test method from scenario")
99
+ end
100
+
101
+ should "create a Scenario" do
102
+ @feature_without_errors.Scenario "pending scenario"
103
+ end
104
+
105
+ should "include the created Scenario in the return value of the 'scenarios' method" do
106
+ scenario = @feature_without_errors.Scenario "pending scenario"
107
+ assert(@feature_without_errors.scenarios.include?(scenario), "feature.scenarios doesn't contain the expected Scenario object")
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class ScenarioTest < Test::Unit::TestCase
4
+ context "A Scenario" do
5
+ setup do
6
+ @scenario = Scenario.new("foobar")
7
+ end
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
+ context "when instantiated" do
16
+ context "with only a String" do
17
+ setup do
18
+ @scenario = Scenario.new("foobar")
19
+ end
20
+
21
+ should "be pending" do
22
+ assert(@scenario.pending?)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,28 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
6
+ require 'coulda'
7
+
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 ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coulda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Evan David Light
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-12 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: jeremymcanally-pending
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.1"
24
+ version:
25
+ description: Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse
26
+ email: evan@tiggerpalace.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .gitignore
36
+ - HISTORY
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - coulda.gemspec
42
+ - example/sample.rb
43
+ - lib/coulda.rb
44
+ - lib/coulda/feature.rb
45
+ - lib/coulda/scenario.rb
46
+ - test/feature_test.rb
47
+ - test/scenario_test.rb
48
+ - test/test_helper.rb
49
+ has_rdoc: true
50
+ homepage: http://evan.tiggerpalace.com/
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --charset=UTF-8
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Behaviour Driven Development derived from Cucumber but as an internal DSL with methods for reuse
77
+ test_files:
78
+ - test/feature_test.rb
79
+ - test/scenario_test.rb
80
+ - test/test_helper.rb