always_execute 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "shared_should", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.5.2"
13
+ gem "rcov", ">= 0"
14
+ gem "mocha", ">= 0"
15
+ end
16
+
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ mocha (0.9.8)
10
+ rake
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ shared_should (0.8.1)
14
+ shoulda
15
+ shoulda (2.10.3)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ bundler (~> 1.0.0)
22
+ jeweler (~> 1.5.2)
23
+ mocha
24
+ rcov
25
+ shared_should
26
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Michael Pearce
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Always Execute - Change the way you test!
2
+
3
+ ## Examples
4
+
5
+ # Credits
6
+
7
+ Always Execute is maintained by [Michael Pearce](http://github.com/michaelgpearce) and is funded by [BookRenter.com](http://www.bookrenter.com "BookRenter.com"). Many of the ideas that have inspired Always Execute come
8
+ from practical usage by the Bookrenter software development team and conversations with [Philippe Huibonhoa](http://github.com/phuibonhoa).
9
+
10
+ ![BookRenter.com Logo](http://assets0.bookrenter.com/images/header/bookrenter_logo.gif "BookRenter.com")
11
+
12
+
13
+ # Copyright
14
+
15
+ Copyright (c) 2011 Michael Pearce, Bookrenter.com. See LICENSE.txt for further details.
16
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "always_execute"
16
+ gem.homepage = "http://github.com/michaelgpearce/always_execute"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Adds execute and expect test blocks for added BDD test clarity.}
19
+ gem.description = %Q{Adds execute and expect test blocks for added BDD test clarity.}
20
+ gem.email = "michael.pearce@bookrenter.com"
21
+ gem.authors = ["Michael Pearce"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'shoulda', '>= 0'
25
+ gem.add_development_dependency 'shoulda', '>= 0'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "always_execute #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
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{always_execute}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael Pearce"]
12
+ s.date = %q{2011-08-19}
13
+ s.description = %q{Adds execute and expect test blocks for added BDD test clarity.}
14
+ s.email = %q{michael.pearce@bookrenter.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "always_execute.gemspec",
28
+ "lib/always_execute.rb",
29
+ "lib/shoulda_execute.rb",
30
+ "lib/shoulda_expects.rb",
31
+ "test/helper.rb",
32
+ "test/test_shoulda_execute.rb",
33
+ "test/test_shoulda_expects.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/michaelgpearce/always_execute}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.5.2}
39
+ s.summary = %q{Adds execute and expect test blocks for added BDD test clarity.}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_shoulda_execute.rb",
43
+ "test/test_shoulda_expects.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_development_dependency(%q<shared_should>, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ s.add_development_dependency(%q<mocha>, [">= 0"])
56
+ s.add_runtime_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<shared_should>, [">= 0"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ s.add_dependency(%q<mocha>, [">= 0"])
65
+ s.add_dependency(%q<shoulda>, [">= 0"])
66
+ s.add_dependency(%q<shoulda>, [">= 0"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<shoulda>, [">= 0"])
70
+ s.add_dependency(%q<shared_should>, [">= 0"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
73
+ s.add_dependency(%q<rcov>, [">= 0"])
74
+ s.add_dependency(%q<mocha>, [">= 0"])
75
+ s.add_dependency(%q<shoulda>, [">= 0"])
76
+ s.add_dependency(%q<shoulda>, [">= 0"])
77
+ end
78
+ end
79
+
@@ -0,0 +1,5 @@
1
+ require 'shoulda'
2
+
3
+ require 'shoulda_execute'
4
+ require 'shoulda_expects'
5
+
@@ -0,0 +1,37 @@
1
+ class Shoulda::Context
2
+ def execute(&execute_block)
3
+ setup do
4
+ @execute_block = execute_block
5
+ end
6
+ end
7
+
8
+ alias :should_without_execute :should
9
+
10
+ def should(name = nil, options = {}, &block)
11
+ if block.nil?
12
+ should_without_execute(name, options)
13
+ else
14
+ should_without_execute(name, options) do
15
+ if @execute_block
16
+ puts self
17
+ self.instance_variable_set('@execute_result', Shoulda::Context.shoulda_execute_call_block(self, @execute_block))
18
+ end
19
+ Shoulda::Context.shoulda_execute_call_block(self, block)
20
+ end
21
+ end
22
+ end
23
+
24
+ def self.shoulda_execute_call_block(test, block)
25
+ if should_execute_shared_should_available?
26
+ test.call_block_with_shared_value(block)
27
+ else
28
+ block.bind(test).call
29
+ end
30
+ end
31
+
32
+ def self.should_execute_shared_should_available?
33
+ Test::Unit::TestCase.respond_to? :share_context
34
+ true
35
+ end
36
+ end
37
+
@@ -0,0 +1,14 @@
1
+ class Shoulda::Context
2
+ def expects(name = nil, &expects_block)
3
+ context nil do
4
+ setup do
5
+ expects_block.bind(self).call
6
+ end
7
+
8
+ should "meet expectation #{name}" do
9
+ # empty body
10
+ end
11
+ end
12
+ end
13
+ end
14
+
data/test/helper.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+ require 'shared_should'
13
+ require 'mocha'
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+ require 'always_execute'
18
+
19
+ class Test::Unit::TestCase
20
+ end
@@ -0,0 +1,68 @@
1
+ require "helper"
2
+
3
+ class TestShouldaExecute < Test::Unit::TestCase
4
+ context ".execute" do
5
+ context "with execute_result on execute" do
6
+ execute do
7
+ :success
8
+ end
9
+
10
+ context "with shared_should library" do
11
+ setup do
12
+ assert TestShouldaExecute.respond_to? :share_should
13
+ end
14
+
15
+ should "set execute_result to execute block return value" do
16
+ assert_equal :success, @execute_result
17
+ end
18
+ end
19
+
20
+ context "without shared_should library" do
21
+ setup do
22
+ Shoulda::Context.expects(:should_execute_shared_should_available?).at_least_once.returns(false)
23
+ end
24
+
25
+ should "set execute_result to execute block return value" do
26
+ assert_equal :success, @execute_result
27
+ end
28
+ end
29
+ end
30
+
31
+ context "execute in nested contexts" do
32
+ setup do
33
+ @last_step = :setup_level1
34
+ end
35
+
36
+ execute do
37
+ assert_equal :setup_level1, @last_step
38
+ @last_step = :execute_level1
39
+ end
40
+
41
+ should "execute execute_level1" do
42
+ assert_equal @last_step, :execute_level1
43
+ end
44
+
45
+ context "with nested context with no execute" do
46
+ should "execute execute_level1" do
47
+ assert_equal @last_step, :execute_level1
48
+ end
49
+ end
50
+
51
+ context "with nested context with execute override" do
52
+ setup do
53
+ assert_equal :setup_level1, @last_step
54
+ @last_step = :setup_level2
55
+ end
56
+
57
+ execute do
58
+ assert_equal :setup_level2, @last_step
59
+ @last_step = :execute_level2
60
+ end
61
+
62
+ should "execute execute_level2" do
63
+ assert_equal @last_step, :execute_level2
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,61 @@
1
+ require "helper"
2
+
3
+ class TestShouldaExpects < Test::Unit::TestCase
4
+ context ".expects" do
5
+ setup do
6
+ @object = mock
7
+ end
8
+
9
+ context "with met expectation" do
10
+ execute do
11
+ @object.call_me
12
+ end
13
+
14
+ expects "call_me to be called" do
15
+ @object.expects(:call_me)
16
+ end
17
+
18
+ expects "call_me to be called second time" do
19
+ @object.expects(:call_me)
20
+ end
21
+ end
22
+
23
+ context "execution order" do
24
+ setup do
25
+ @last_step = :setup
26
+ end
27
+
28
+ context "with 'expects'" do
29
+ execute do
30
+ assert_equal :expects, @last_step
31
+ @last_step = :execute
32
+ end
33
+
34
+ expects "to be called before execute" do
35
+ assert_equal :setup, @last_step
36
+ @last_step = :expects
37
+ end
38
+ end
39
+
40
+ context "with 'expects' and 'should'" do
41
+ setup do
42
+ @expects_called = false
43
+ end
44
+
45
+ execute do
46
+ assert_equal :setup, @last_step
47
+ @last_step = :execute
48
+ end
49
+
50
+ expects do
51
+ @expects_called = true
52
+ end
53
+
54
+ should "not call 'expects' for 'should'" do
55
+ assert_equal :execute, @last_step
56
+ assert !@expects_called
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: always_execute
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Michael Pearce
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-19 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ prerelease: false
33
+ type: :development
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: shared_should
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ prerelease: false
47
+ type: :development
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ hash: 23
57
+ segments:
58
+ - 1
59
+ - 0
60
+ - 0
61
+ version: 1.0.0
62
+ prerelease: false
63
+ type: :development
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: jeweler
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ hash: 7
73
+ segments:
74
+ - 1
75
+ - 5
76
+ - 2
77
+ version: 1.5.2
78
+ prerelease: false
79
+ type: :development
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: rcov
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ prerelease: false
93
+ type: :development
94
+ requirement: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: mocha
97
+ version_requirements: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ prerelease: false
107
+ type: :development
108
+ requirement: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: shoulda
111
+ version_requirements: &id007 !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ prerelease: false
121
+ type: :runtime
122
+ requirement: *id007
123
+ - !ruby/object:Gem::Dependency
124
+ name: shoulda
125
+ version_requirements: &id008 !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ prerelease: false
135
+ type: :development
136
+ requirement: *id008
137
+ description: Adds execute and expect test blocks for added BDD test clarity.
138
+ email: michael.pearce@bookrenter.com
139
+ executables: []
140
+
141
+ extensions: []
142
+
143
+ extra_rdoc_files:
144
+ - LICENSE.txt
145
+ - README.md
146
+ files:
147
+ - .document
148
+ - Gemfile
149
+ - Gemfile.lock
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - VERSION
154
+ - always_execute.gemspec
155
+ - lib/always_execute.rb
156
+ - lib/shoulda_execute.rb
157
+ - lib/shoulda_expects.rb
158
+ - test/helper.rb
159
+ - test/test_shoulda_execute.rb
160
+ - test/test_shoulda_expects.rb
161
+ has_rdoc: true
162
+ homepage: http://github.com/michaelgpearce/always_execute
163
+ licenses:
164
+ - MIT
165
+ post_install_message:
166
+ rdoc_options: []
167
+
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ hash: 3
176
+ segments:
177
+ - 0
178
+ version: "0"
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ hash: 3
185
+ segments:
186
+ - 0
187
+ version: "0"
188
+ requirements: []
189
+
190
+ rubyforge_project:
191
+ rubygems_version: 1.5.2
192
+ signing_key:
193
+ specification_version: 3
194
+ summary: Adds execute and expect test blocks for added BDD test clarity.
195
+ test_files:
196
+ - test/helper.rb
197
+ - test/test_shoulda_execute.rb
198
+ - test/test_shoulda_expects.rb