always_execute 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,16 +1,5 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
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
3
+ # always_execute.gemspec
4
+ gemspec
16
5
 
data/Gemfile.lock CHANGED
@@ -1,26 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ always_execute (0.0.2)
5
+ always_execute
6
+ shoulda
7
+
1
8
  GEM
2
9
  remote: http://rubygems.org/
3
10
  specs:
11
+ diff-lcs (1.1.3)
4
12
  git (1.2.5)
5
- jeweler (1.5.2)
6
- bundler (~> 1.0.0)
13
+ jeweler (1.6.4)
14
+ bundler (~> 1.0)
7
15
  git (>= 1.2.5)
8
16
  rake
17
+ minitest (2.12.1)
9
18
  mocha (0.9.8)
10
19
  rake
11
- rake (0.8.7)
20
+ rake (0.9.2.2)
12
21
  rcov (0.9.9)
13
- shared_should (0.8.1)
22
+ rspec (2.11.0)
23
+ rspec-core (~> 2.11.0)
24
+ rspec-expectations (~> 2.11.0)
25
+ rspec-mocks (~> 2.11.0)
26
+ rspec-core (2.11.1)
27
+ rspec-expectations (2.11.2)
28
+ diff-lcs (~> 1.1.3)
29
+ rspec-mocks (2.11.1)
30
+ shared_should (0.8.3)
14
31
  shoulda
15
- shoulda (2.10.3)
32
+ shoulda (2.11.3)
16
33
 
17
34
  PLATFORMS
18
35
  ruby
19
36
 
20
37
  DEPENDENCIES
21
- bundler (~> 1.0.0)
22
- jeweler (~> 1.5.2)
38
+ always_execute!
39
+ bundler (>= 1.0.0)
40
+ jeweler (>= 1.5.2)
41
+ minitest (>= 2.12.1)
23
42
  mocha
24
43
  rcov
25
- shared_should
26
- shoulda
44
+ rspec (>= 2.9.0)
45
+ shared_should (>= 0.8.3)
46
+ shoulda (>= 2.11.3)
data/README.md CHANGED
@@ -1,16 +1,27 @@
1
1
  # Always Execute - Change the way you test!
2
2
 
3
- ## Examples
3
+ Always Execute extends [RSpec](http://rspec.info) or [Shoulda](https://github.com/thoughtbot/shoulda) by adding an execute block, which is the natural home for the actual code you are testing. Why would you ever need that? The answer is simple, the execute block provides a clear separation of concerns in your test structure making it easier to read and write.
4
+
5
+ All good tests have 3 separate and equally important steps:
6
+
7
+ 1. **_Setup_** the environment in a known state
8
+ 2. **_Execute_** the code you want to test
9
+ 3. **_Assert_** that your code changed the environment in the way you expected
10
+
11
+ Both RSpec and Shoulda by default provide blocks to encapsulate the **_setup_** and **_assert_** steps with the `before` / `setup` and `it` / `should` blocks, but there is no built-in block for the **_execute_** step. This leads to muddled blocks for your assertions that often contain bits of **_setup_**, **_execute_**, and **_assert_** code, making the test difficult to understand.
12
+
13
+ Checkout the examples:
14
+
15
+ [RSpec Examples](doc/rspec_examples.md)
16
+ [Shoulda Examples](doc/shoulda_examples.md)
4
17
 
5
18
  # Credits
6
19
 
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).
20
+ Always Execute was developed by [Michael Pearce](http://github.com/michaelgpearce) in conjunction with [Philippe Huibonhoa](http://github.com/phuibonhoa) and is funded by [BookRenter.com](http://www.bookrenter.com "BookRenter.com").
9
21
 
10
22
  ![BookRenter.com Logo](http://assets0.bookrenter.com/images/header/bookrenter_logo.gif "BookRenter.com")
11
23
 
12
24
 
13
25
  # Copyright
14
26
 
15
- Copyright (c) 2011 Michael Pearce, Bookrenter.com. See LICENSE.txt for further details.
16
-
27
+ Copyright (c) 2011 Michael Pearce, Bookrenter.com. See LICENSE.txt for further details.``
data/Rakefile CHANGED
@@ -22,7 +22,12 @@ Jeweler::Tasks.new do |gem|
22
22
  # Include your dependencies below. Runtime dependencies are required when using your gem,
23
23
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
24
  gem.add_runtime_dependency 'shoulda', '>= 0'
25
- gem.add_development_dependency 'shoulda', '>= 0'
25
+ gem.add_development_dependency 'shoulda', '>= 2.11.3'
26
+ gem.add_development_dependency 'rspec', '>= 2.9.0'
27
+ gem.add_development_dependency 'shared_should', '>= 0.8.3'
28
+ gem.add_development_dependency 'rcov', '>= 0'
29
+ gem.add_development_dependency 'mocha', '>= 0'
30
+ gem.add_development_dependency 'minitest', '>= 2.12.1'
26
31
  end
27
32
  Jeweler::RubygemsDotOrgTasks.new
28
33
 
@@ -33,16 +38,11 @@ Rake::TestTask.new(:test) do |test|
33
38
  test.verbose = true
34
39
  end
35
40
 
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
41
+ require 'rspec/core/rake_task'
42
+ desc "Run Rspecs"
43
+ RSpec::Core::RakeTask.new(:spec)
42
44
 
43
- task :default => :test
44
-
45
- require 'rake/rdoctask'
45
+ require 'rdoc/task'
46
46
  Rake::RDocTask.new do |rdoc|
47
47
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
48
 
@@ -51,3 +51,6 @@ Rake::RDocTask.new do |rdoc|
51
51
  rdoc.rdoc_files.include('README*')
52
52
  rdoc.rdoc_files.include('lib/**/*.rb')
53
53
  end
54
+
55
+ task :default => [:test, :spec]
56
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{always_execute}
8
- s.version = "0.0.2"
7
+ s.name = "always_execute"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Pearce"]
12
- s.date = %q{2011-08-22}
13
- s.description = %q{Adds execute and expect test blocks for added BDD test clarity.}
14
- s.email = %q{michael.pearce@bookrenter.com}
12
+ s.date = "2012-08-09"
13
+ s.description = "Adds execute and expect test blocks for added BDD test clarity."
14
+ s.email = "michael.pearce@bookrenter.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.md"
@@ -25,55 +25,96 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "always_execute.gemspec",
28
+ "docs/rspec_examples.md",
29
+ "docs/shoulda_examples.md",
28
30
  "lib/always_execute.rb",
31
+ "lib/rspec_execute.rb",
32
+ "lib/rspec_expects.rb",
29
33
  "lib/shoulda_execute.rb",
30
34
  "lib/shoulda_expects.rb",
35
+ "spec/execute_spec.rb",
36
+ "spec/expects_spec.rb",
37
+ "spec/spec_helper.rb",
31
38
  "test/helper.rb",
32
39
  "test/shoulda_execute_test.rb",
33
40
  "test/shoulda_expects_test.rb"
34
41
  ]
35
- s.homepage = %q{http://github.com/michaelgpearce/always_execute}
42
+ s.homepage = "http://github.com/michaelgpearce/always_execute"
36
43
  s.licenses = ["MIT"]
37
44
  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/shoulda_execute_test.rb",
43
- "test/shoulda_expects_test.rb"
44
- ]
45
+ s.rubygems_version = "1.8.24"
46
+ s.summary = "Adds execute and expect test blocks for added BDD test clarity."
45
47
 
46
48
  if s.respond_to? :specification_version then
47
49
  s.specification_version = 3
48
50
 
49
51
  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"])
52
+ s.add_runtime_dependency(%q<always_execute>, [">= 0"])
53
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
54
+ s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
54
55
  s.add_development_dependency(%q<rcov>, [">= 0"])
55
56
  s.add_development_dependency(%q<mocha>, [">= 0"])
57
+ s.add_development_dependency(%q<rspec>, [">= 2.9.0"])
58
+ s.add_development_dependency(%q<rcov>, [">= 0"])
59
+ s.add_development_dependency(%q<mocha>, [">= 0"])
60
+ s.add_development_dependency(%q<shoulda>, [">= 2.11.3"])
61
+ s.add_development_dependency(%q<rspec>, [">= 2.9.0"])
62
+ s.add_development_dependency(%q<shared_should>, [">= 0.8.3"])
63
+ s.add_development_dependency(%q<rcov>, [">= 0"])
64
+ s.add_development_dependency(%q<mocha>, [">= 0"])
65
+ s.add_development_dependency(%q<minitest>, [">= 2.12.1"])
56
66
  s.add_runtime_dependency(%q<shoulda>, [">= 0"])
57
- s.add_development_dependency(%q<shoulda>, [">= 0"])
67
+ s.add_development_dependency(%q<shoulda>, [">= 2.11.3"])
68
+ s.add_development_dependency(%q<rspec>, [">= 2.9.0"])
69
+ s.add_development_dependency(%q<shared_should>, [">= 0.8.3"])
70
+ s.add_development_dependency(%q<rcov>, [">= 0"])
71
+ s.add_development_dependency(%q<mocha>, [">= 0"])
72
+ s.add_development_dependency(%q<minitest>, [">= 2.12.1"])
58
73
  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"])
74
+ s.add_dependency(%q<always_execute>, [">= 0"])
75
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
76
+ s.add_dependency(%q<jeweler>, [">= 1.5.2"])
63
77
  s.add_dependency(%q<rcov>, [">= 0"])
64
78
  s.add_dependency(%q<mocha>, [">= 0"])
79
+ s.add_dependency(%q<rspec>, [">= 2.9.0"])
80
+ s.add_dependency(%q<rcov>, [">= 0"])
81
+ s.add_dependency(%q<mocha>, [">= 0"])
82
+ s.add_dependency(%q<shoulda>, [">= 2.11.3"])
83
+ s.add_dependency(%q<rspec>, [">= 2.9.0"])
84
+ s.add_dependency(%q<shared_should>, [">= 0.8.3"])
85
+ s.add_dependency(%q<rcov>, [">= 0"])
86
+ s.add_dependency(%q<mocha>, [">= 0"])
87
+ s.add_dependency(%q<minitest>, [">= 2.12.1"])
65
88
  s.add_dependency(%q<shoulda>, [">= 0"])
66
- s.add_dependency(%q<shoulda>, [">= 0"])
89
+ s.add_dependency(%q<shoulda>, [">= 2.11.3"])
90
+ s.add_dependency(%q<rspec>, [">= 2.9.0"])
91
+ s.add_dependency(%q<shared_should>, [">= 0.8.3"])
92
+ s.add_dependency(%q<rcov>, [">= 0"])
93
+ s.add_dependency(%q<mocha>, [">= 0"])
94
+ s.add_dependency(%q<minitest>, [">= 2.12.1"])
67
95
  end
68
96
  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"])
97
+ s.add_dependency(%q<always_execute>, [">= 0"])
98
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
99
+ s.add_dependency(%q<jeweler>, [">= 1.5.2"])
73
100
  s.add_dependency(%q<rcov>, [">= 0"])
74
101
  s.add_dependency(%q<mocha>, [">= 0"])
102
+ s.add_dependency(%q<rspec>, [">= 2.9.0"])
103
+ s.add_dependency(%q<rcov>, [">= 0"])
104
+ s.add_dependency(%q<mocha>, [">= 0"])
105
+ s.add_dependency(%q<shoulda>, [">= 2.11.3"])
106
+ s.add_dependency(%q<rspec>, [">= 2.9.0"])
107
+ s.add_dependency(%q<shared_should>, [">= 0.8.3"])
108
+ s.add_dependency(%q<rcov>, [">= 0"])
109
+ s.add_dependency(%q<mocha>, [">= 0"])
110
+ s.add_dependency(%q<minitest>, [">= 2.12.1"])
75
111
  s.add_dependency(%q<shoulda>, [">= 0"])
76
- s.add_dependency(%q<shoulda>, [">= 0"])
112
+ s.add_dependency(%q<shoulda>, [">= 2.11.3"])
113
+ s.add_dependency(%q<rspec>, [">= 2.9.0"])
114
+ s.add_dependency(%q<shared_should>, [">= 0.8.3"])
115
+ s.add_dependency(%q<rcov>, [">= 0"])
116
+ s.add_dependency(%q<mocha>, [">= 0"])
117
+ s.add_dependency(%q<minitest>, [">= 2.12.1"])
77
118
  end
78
119
  end
79
120
 
@@ -0,0 +1,125 @@
1
+
2
+ # RSpec Examples
3
+
4
+ ## Without Always Execute
5
+
6
+ Notice in the test below there is **_setup_**, **_execute_**, and **_assert_** code all in the `it` blocks. Different test cases are not separated by contexts, instead they're all just strewn together; it may not be immediately obvious, but we're really testing 3 different cases below (not 4 - the first 2 `it`s describe the default behavior of the dvd\_player). It's easy to see how these problems could be much worse given a less trivial example and how these tests would not serve as the best documentation of how dvd_player#play works.
7
+
8
+ ```ruby
9
+ describe "dvd player" do
10
+ before do
11
+ @dvd_player = DvdPlayer.new
12
+ @dvd = Dvd.new
13
+ end
14
+
15
+ it "should play movie" do
16
+ @dvd_player.play(@dvd)
17
+ @dvd_player.movie_playing?.should be_true
18
+ end
19
+
20
+ it "should not allow another disc to be inserted" do
21
+ @dvd_player.play(@dvd)
22
+ @dvd_player.allows_disc_insert?.should be_false
23
+ end
24
+
25
+ it "should not play movie with invalid region code" do
26
+ @dvd.region_code = 'invalid'
27
+ @dvd_player.play(@dvd)
28
+ @dvd_player.movie_playing?.should be_false
29
+ end
30
+
31
+ it "should resume from last played postiion with previously played dvd" do
32
+ @dvd.last_played_position = 123
33
+ @dvd_player.play(@dvd)
34
+ @dvd_player.movie_playing?.should be_true
35
+ @dvd_player.current_position.should == 123
36
+ end
37
+ end
38
+ ```
39
+
40
+ ## With Always Execute
41
+
42
+ When using always execute, you'll notice it's a lot DRYer, but more importantly all the **_setup_**, **_execute_**, and **_assert_** code is cleanly separated. Furthermore, test cases are cleanly separated by contexts. This makes it much easier to see that the first two should blocks apply to the default case, whereas the following contexts apply to exception cases. It's also much easier to see what makes the exception cases different, since their **_setup_** code is cleanly spelled out, rather than lumped in with other code.
43
+
44
+ ```ruby
45
+ describe "dvd player" do
46
+ context "#play" do
47
+ before do
48
+ @dvd_player = DvdPlayer.new
49
+ @dvd = Dvd.new
50
+ end
51
+
52
+ execute do
53
+ @dvd_player.play(@dvd)
54
+ end
55
+
56
+
57
+ it "should play movie" do
58
+ @dvd_player.movie_playing?.should be_true
59
+ end
60
+
61
+ it "should not allow another disc to be inserted" do
62
+ @dvd_player.allows_disc_insert?.should be_false
63
+ end
64
+
65
+ context "with invalid region code" do
66
+ before do
67
+ @dvd.region_code = 'invalid'
68
+ end
69
+
70
+ it "should not play movie" do
71
+ @dvd_player.movie_playing?.should be_false
72
+ end
73
+ end
74
+
75
+ context "with previously played dvd" do
76
+ before do
77
+ @dvd.last_played_position = 123
78
+ end
79
+
80
+ it "should resume from last played position" do
81
+ @dvd_player.movie_playing?.should be_true
82
+ @dvd_player.current_position.should == 123
83
+ end
84
+ end
85
+ end
86
+ end
87
+ ```
88
+
89
+ # Other Features
90
+
91
+ ## execute_result
92
+
93
+ Often in specs, you are testing the returned value of a single function. For connivence, the returned value of an execute block is stored in a variable called `@execute_result`.
94
+
95
+ ```ruby
96
+ describe "dvd player" do
97
+ context "#current_dvd" do
98
+ before do
99
+ @dvd_player = DvdPlayer.new
100
+ end
101
+
102
+ execute do
103
+ @dvd_player.current_dvd
104
+ end
105
+
106
+ context "without any dvd in the player" do
107
+ it "should return no dvd" do
108
+ @execute_result.should be_nil
109
+ end
110
+ end
111
+
112
+ context "with a dvd in the player" do
113
+ before do
114
+ @dvd = Dvd.new
115
+ @dvd_player.insert(@dvd)
116
+ end
117
+
118
+ it "should return the dvd in the player" do
119
+ @execute_result.should == @dvd
120
+ end
121
+ end
122
+ end
123
+ end
124
+ ```
125
+
@@ -0,0 +1,149 @@
1
+
2
+ # Shoulda Examples
3
+
4
+ ## Without Always Execute
5
+
6
+ Notice in the test below there is **_setup_**, **_execute_**, and **_assert_** code all in the `should` blocks. Different test cases are not separated by contexts, instead they're all just strewn together; it may not be immediately obvious, but we're really testing 3 different cases below (not 4 - the first 2 shoulds describe the default behavior of the dvd\_player). It's easy to see how these problems could be much worse given a less trivial example and how these tests would not serve as the best documentation of how dvd_player#play works.
7
+
8
+ ```ruby
9
+ class DvdPlayerTest
10
+ context "dvd player" do
11
+ setup do
12
+ @dvd_player = DvdPlayer.new
13
+ @dvd = Dvd.new
14
+ end
15
+
16
+ should "play movie" do
17
+ @dvd_player.play(@dvd)
18
+ assert @dvd_player.movie_playing?
19
+ end
20
+
21
+ should "not allow another disc to be inserted" do
22
+ @dvd_player.play(@dvd)
23
+ assert_equal false, @dvd_player.allows_disc_insert?
24
+ end
25
+
26
+ should "not play movie with invalid region code" do
27
+ @dvd.region_code = 'invalid'
28
+ @dvd_player.play(@dvd)
29
+ assert_equal false, @dvd_player.movie_playing?
30
+ end
31
+
32
+ should "resume from last played postiion with previously played dvd" do
33
+ @dvd.last_played_position = 123
34
+ @dvd_player.play(@dvd)
35
+ assert @dvd_player.movie_playing?
36
+ assert_equal 123, @dvd_player.current_position
37
+ end
38
+ end
39
+ end
40
+ ```
41
+
42
+ ## With Always Execute
43
+
44
+ When using always execute, you'll notice it's a lot DRYer, but more importantly all the **_setup_**, **_execute_**, and **_assert_** code is cleanly separated. Furthermore, test cases are cleanly separated by contexts. This makes it much easier to see that the first two should blocks apply to the default case, whereas the following contexts apply to exception cases. It's also much easier to see what makes the exception cases different, since their **_setup_** code is cleanly spelled out, rather than lumped in with other code.
45
+
46
+ ```ruby
47
+ class DvdPlayerTest
48
+ context "#play" do
49
+ setup do
50
+ @dvd_player = DvdPlayer.new
51
+ @dvd = Dvd.new
52
+ end
53
+
54
+ execute do
55
+ @dvd_player.play(@dvd)
56
+ end
57
+
58
+
59
+ should "play movie" do
60
+ assert @dvd_player.movie_playing?
61
+ end
62
+
63
+ should "not allow another disc to be inserted" do
64
+ assert_equal false, @dvd_player.allows_disc_insert?
65
+ end
66
+
67
+ context "with invalid region code" do
68
+ setup do
69
+ @dvd.region_code = 'invalid'
70
+ end
71
+
72
+ should "not play movie" do
73
+ assert_equal false, @dvd_player.movie_playing?
74
+ end
75
+ end
76
+
77
+ context "with previously played dvd" do
78
+ setup do
79
+ @dvd.last_played_position = 123
80
+ end
81
+
82
+ should "resume from last played position" do
83
+ assert @dvd_player.movie_playing?
84
+ assert_equal 123, @dvd_player.current_position
85
+ end
86
+ end
87
+ end
88
+ end
89
+ ```
90
+
91
+ # Other Features
92
+
93
+ ## execute_result
94
+
95
+ Often in unit tests, you are testing the returned value of a single function. For connivence, the returned value of an execute block is stored in a variable called `@execute_result`.
96
+
97
+ ```ruby
98
+ class DvdPlayerTest
99
+ context "#current_dvd" do
100
+ setup do
101
+ @dvd_player = DvdPlayer.new
102
+ end
103
+
104
+ execute do
105
+ @dvd_player.current_dvd
106
+ end
107
+
108
+ context "without any dvd in the player" do
109
+ should "return no dvd" do
110
+ assert_nil @execute_result
111
+ end
112
+ end
113
+
114
+ context "with a dvd in the player" do
115
+ setup do
116
+ @dvd = Dvd.new
117
+ @dvd_player.insert(@dvd)
118
+ end
119
+
120
+ should "return the dvd in the player" do
121
+ assert_equal @dvd, @execute_result
122
+ end
123
+ end
124
+ end
125
+ end
126
+ ```
127
+
128
+ ## expects
129
+
130
+ Expectations belong in the **_assert_** step of testing, but because of the nature of mocha expectations they need to be called in your `setup` block. The `expects` block allows you to set your expectations without needing to create a new context.
131
+
132
+ ```ruby
133
+ class DvdPlayerTest
134
+ context "#menu" do
135
+ setup do
136
+ @dvd_player = DvdPlayer.new
137
+ end
138
+
139
+ execute do
140
+ @dvd_player.menu
141
+ end
142
+
143
+ expects do
144
+ @dvd_player.expects(:display_menu_options)
145
+ end
146
+ end
147
+ end
148
+ ```
149
+
@@ -1,5 +1,9 @@
1
- require 'shoulda'
2
-
3
- require 'shoulda_execute'
4
- require 'shoulda_expects'
1
+ if defined?(Shoulda)
2
+ require 'shoulda_execute'
3
+ require 'shoulda_expects'
4
+ end
5
5
 
6
+ if defined?(RSpec)
7
+ require 'rspec_execute'
8
+ require 'rspec_expects'
9
+ end
@@ -0,0 +1,29 @@
1
+ module RSpec
2
+ module Core
3
+ class Example
4
+ alias :initialize_without_execute :initialize
5
+
6
+ def initialize(example_group_class, description, metadata, example_block=nil)
7
+ if example_block
8
+ example_block_with_execute = Proc.new do |*args|
9
+ if @execute_block
10
+ self.instance_variable_set('@execute_result', instance_exec(&@execute_block))
11
+ end
12
+ instance_exec(*args, &example_block)
13
+ end
14
+ end
15
+
16
+ initialize_without_execute(example_group_class, description, metadata, example_block_with_execute)
17
+ end
18
+ end
19
+
20
+ class ExampleGroup
21
+ def self.execute(&execute_block)
22
+ before do
23
+ @execute_block = execute_block
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,18 @@
1
+ module RSpec
2
+ module Core
3
+ class ExampleGroup
4
+ def self.expects(name = nil, &expects_block)
5
+ describe nil do
6
+ before do
7
+ instance_exec(&expects_block)
8
+ end
9
+
10
+ it "should meet expectation #{name}" do
11
+ # empty body
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe ".execute" do
4
+ context "with execute_result on execute" do
5
+ execute do
6
+ :success
7
+ end
8
+
9
+ it "should set execute_result to execute block return value" do
10
+ :success.should == @execute_result
11
+ end
12
+ end
13
+
14
+ context "execute in nested contexts" do
15
+ before do
16
+ @last_step = :before_level1
17
+ end
18
+
19
+ execute do
20
+ :before_level1.should == @last_step
21
+ @last_step = :execute_level1
22
+ end
23
+
24
+ it "should execute execute_level1" do
25
+ @last_step.should == :execute_level1
26
+ end
27
+
28
+ context "with nested context with no execute" do
29
+ it "should execute execute_level1" do
30
+ @last_step.should == :execute_level1
31
+ end
32
+ end
33
+
34
+ context "with nested context with execute override" do
35
+ before do
36
+ :before_level1.should == @last_step
37
+ @last_step = :before_level2
38
+ end
39
+
40
+ execute do
41
+ :before_level2.should == @last_step
42
+ @last_step = :execute_level2
43
+ end
44
+
45
+ it "should execute execute_level2" do
46
+ @last_step.should == :execute_level2
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+
3
+ describe ".expects" do
4
+ before do
5
+ @object = mock
6
+ end
7
+
8
+ context "with met expectation" do
9
+ execute do
10
+ @object.call_me
11
+ end
12
+
13
+ expects "call_me to be called" do
14
+ @object.should_receive(:call_me)
15
+ end
16
+
17
+ expects "call_me to be called second time" do
18
+ @object.should_receive(:call_me)
19
+ end
20
+ end
21
+
22
+ context "execution order" do
23
+ before do
24
+ @last_step = :before
25
+ end
26
+
27
+ context "with 'expects'" do
28
+ execute do
29
+ :expects.should == @last_step
30
+ @last_step = :execute
31
+ end
32
+
33
+ expects "to be called before execute" do
34
+ :before.should == @last_step
35
+ @last_step = :expects
36
+ end
37
+ end
38
+
39
+ context "with 'expects' and 'it'" do
40
+ before do
41
+ @expects_called = false
42
+ end
43
+
44
+ execute do
45
+ :before.should == @last_step
46
+ @last_step = :execute
47
+ end
48
+
49
+ expects do
50
+ @expects_called = true
51
+ end
52
+
53
+ it "should not call 'expects' for 'it'" do
54
+ :execute.should == @last_step
55
+ @expects_called.should be_false
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'always_execute'
metadata CHANGED
@@ -1,149 +1,360 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: always_execute
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Michael Pearce
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-22 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
12
+ date: 2012-08-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: always_execute
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
32
23
  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
24
+ version_requirements: !ruby/object:Gem::Requirement
38
25
  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
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
50
31
  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
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
61
37
  version: 1.0.0
62
- prerelease: false
63
38
  type: :development
64
- requirement: *id003
65
- - !ruby/object:Gem::Dependency
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
66
47
  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
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
77
53
  version: 1.5.2
54
+ type: :development
78
55
  prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: rcov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
79
70
  type: :development
80
- requirement: *id004
81
- - !ruby/object:Gem::Dependency
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: mocha
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 2.9.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 2.9.0
110
+ - !ruby/object:Gem::Dependency
82
111
  name: rcov
83
- version_requirements: &id005 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: mocha
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: shoulda
144
+ requirement: !ruby/object:Gem::Requirement
84
145
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: 2.11.3
150
+ type: :development
92
151
  prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: 2.11.3
158
+ - !ruby/object:Gem::Dependency
159
+ name: rspec
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: 2.9.0
93
166
  type: :development
94
- requirement: *id005
95
- - !ruby/object:Gem::Dependency
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: 2.9.0
174
+ - !ruby/object:Gem::Dependency
175
+ name: shared_should
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: 0.8.3
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: 0.8.3
190
+ - !ruby/object:Gem::Dependency
191
+ name: rcov
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ - !ruby/object:Gem::Dependency
96
207
  name: mocha
97
- version_requirements: &id006 !ruby/object:Gem::Requirement
208
+ requirement: !ruby/object:Gem::Requirement
98
209
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ type: :development
106
215
  prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ - !ruby/object:Gem::Dependency
223
+ name: minitest
224
+ requirement: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: 2.12.1
107
230
  type: :development
108
- requirement: *id006
109
- - !ruby/object:Gem::Dependency
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: 2.12.1
238
+ - !ruby/object:Gem::Dependency
110
239
  name: shoulda
111
- version_requirements: &id007 !ruby/object:Gem::Requirement
240
+ requirement: !ruby/object:Gem::Requirement
112
241
  none: false
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
118
- - 0
119
- version: "0"
120
- prerelease: false
242
+ requirements:
243
+ - - ! '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
121
246
  type: :runtime
122
- requirement: *id007
123
- - !ruby/object:Gem::Dependency
247
+ prerelease: false
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ none: false
250
+ requirements:
251
+ - - ! '>='
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
254
+ - !ruby/object:Gem::Dependency
124
255
  name: shoulda
125
- version_requirements: &id008 !ruby/object:Gem::Requirement
256
+ requirement: !ruby/object:Gem::Requirement
257
+ none: false
258
+ requirements:
259
+ - - ! '>='
260
+ - !ruby/object:Gem::Version
261
+ version: 2.11.3
262
+ type: :development
263
+ prerelease: false
264
+ version_requirements: !ruby/object:Gem::Requirement
265
+ none: false
266
+ requirements:
267
+ - - ! '>='
268
+ - !ruby/object:Gem::Version
269
+ version: 2.11.3
270
+ - !ruby/object:Gem::Dependency
271
+ name: rspec
272
+ requirement: !ruby/object:Gem::Requirement
273
+ none: false
274
+ requirements:
275
+ - - ! '>='
276
+ - !ruby/object:Gem::Version
277
+ version: 2.9.0
278
+ type: :development
279
+ prerelease: false
280
+ version_requirements: !ruby/object:Gem::Requirement
281
+ none: false
282
+ requirements:
283
+ - - ! '>='
284
+ - !ruby/object:Gem::Version
285
+ version: 2.9.0
286
+ - !ruby/object:Gem::Dependency
287
+ name: shared_should
288
+ requirement: !ruby/object:Gem::Requirement
289
+ none: false
290
+ requirements:
291
+ - - ! '>='
292
+ - !ruby/object:Gem::Version
293
+ version: 0.8.3
294
+ type: :development
295
+ prerelease: false
296
+ version_requirements: !ruby/object:Gem::Requirement
297
+ none: false
298
+ requirements:
299
+ - - ! '>='
300
+ - !ruby/object:Gem::Version
301
+ version: 0.8.3
302
+ - !ruby/object:Gem::Dependency
303
+ name: rcov
304
+ requirement: !ruby/object:Gem::Requirement
305
+ none: false
306
+ requirements:
307
+ - - ! '>='
308
+ - !ruby/object:Gem::Version
309
+ version: '0'
310
+ type: :development
311
+ prerelease: false
312
+ version_requirements: !ruby/object:Gem::Requirement
126
313
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
- version: "0"
314
+ requirements:
315
+ - - ! '>='
316
+ - !ruby/object:Gem::Version
317
+ version: '0'
318
+ - !ruby/object:Gem::Dependency
319
+ name: mocha
320
+ requirement: !ruby/object:Gem::Requirement
321
+ none: false
322
+ requirements:
323
+ - - ! '>='
324
+ - !ruby/object:Gem::Version
325
+ version: '0'
326
+ type: :development
134
327
  prerelease: false
328
+ version_requirements: !ruby/object:Gem::Requirement
329
+ none: false
330
+ requirements:
331
+ - - ! '>='
332
+ - !ruby/object:Gem::Version
333
+ version: '0'
334
+ - !ruby/object:Gem::Dependency
335
+ name: minitest
336
+ requirement: !ruby/object:Gem::Requirement
337
+ none: false
338
+ requirements:
339
+ - - ! '>='
340
+ - !ruby/object:Gem::Version
341
+ version: 2.12.1
135
342
  type: :development
136
- requirement: *id008
343
+ prerelease: false
344
+ version_requirements: !ruby/object:Gem::Requirement
345
+ none: false
346
+ requirements:
347
+ - - ! '>='
348
+ - !ruby/object:Gem::Version
349
+ version: 2.12.1
137
350
  description: Adds execute and expect test blocks for added BDD test clarity.
138
351
  email: michael.pearce@bookrenter.com
139
352
  executables: []
140
-
141
353
  extensions: []
142
-
143
- extra_rdoc_files:
354
+ extra_rdoc_files:
144
355
  - LICENSE.txt
145
356
  - README.md
146
- files:
357
+ files:
147
358
  - .document
148
359
  - Gemfile
149
360
  - Gemfile.lock
@@ -152,47 +363,45 @@ files:
152
363
  - Rakefile
153
364
  - VERSION
154
365
  - always_execute.gemspec
366
+ - docs/rspec_examples.md
367
+ - docs/shoulda_examples.md
155
368
  - lib/always_execute.rb
369
+ - lib/rspec_execute.rb
370
+ - lib/rspec_expects.rb
156
371
  - lib/shoulda_execute.rb
157
372
  - lib/shoulda_expects.rb
373
+ - spec/execute_spec.rb
374
+ - spec/expects_spec.rb
375
+ - spec/spec_helper.rb
158
376
  - test/helper.rb
159
377
  - test/shoulda_execute_test.rb
160
378
  - test/shoulda_expects_test.rb
161
- has_rdoc: true
162
379
  homepage: http://github.com/michaelgpearce/always_execute
163
- licenses:
380
+ licenses:
164
381
  - MIT
165
382
  post_install_message:
166
383
  rdoc_options: []
167
-
168
- require_paths:
384
+ require_paths:
169
385
  - lib
170
- required_ruby_version: !ruby/object:Gem::Requirement
386
+ required_ruby_version: !ruby/object:Gem::Requirement
171
387
  none: false
172
- requirements:
173
- - - ">="
174
- - !ruby/object:Gem::Version
175
- hash: 3
176
- segments:
388
+ requirements:
389
+ - - ! '>='
390
+ - !ruby/object:Gem::Version
391
+ version: '0'
392
+ segments:
177
393
  - 0
178
- version: "0"
179
- required_rubygems_version: !ruby/object:Gem::Requirement
394
+ hash: -860824188872113324
395
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
396
  none: false
181
- requirements:
182
- - - ">="
183
- - !ruby/object:Gem::Version
184
- hash: 3
185
- segments:
186
- - 0
187
- version: "0"
397
+ requirements:
398
+ - - ! '>='
399
+ - !ruby/object:Gem::Version
400
+ version: '0'
188
401
  requirements: []
189
-
190
402
  rubyforge_project:
191
- rubygems_version: 1.5.2
403
+ rubygems_version: 1.8.24
192
404
  signing_key:
193
405
  specification_version: 3
194
406
  summary: Adds execute and expect test blocks for added BDD test clarity.
195
- test_files:
196
- - test/helper.rb
197
- - test/shoulda_execute_test.rb
198
- - test/shoulda_expects_test.rb
407
+ test_files: []