minitest-context 0.1.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.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ doc/
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - rbx-2.0
6
+ - jruby
7
+ - ruby-head
8
+ - ree
data/.yardopts ADDED
@@ -0,0 +1,9 @@
1
+ --no-private
2
+ -M redcarpet
3
+ -m markdown
4
+ --hide-void-return
5
+ --main README.txt
6
+ -
7
+ README.txt
8
+ LICENSE.txt
9
+
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2011 by Robert Gleeson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
data/README.txt ADDED
@@ -0,0 +1,50 @@
1
+ = minitest/context
2
+
3
+ * Author : Rob Gleeson <rob@flowof.info>
4
+ * Home : https://github.com/robgleeson/minitest-context
5
+ * API : http://rubydoc.info/github/robgleeson/minitest-context/master/frames
6
+ * CI status : http://travis-ci.org/#!/robgleeson/minitest-context
7
+
8
+ == Description
9
+
10
+ minitest/context can define contexts for code reuse in MiniTest specs that share common expectations.
11
+ The idea orginated from the shared_context() and include_context() methods distributed with RSpec.
12
+
13
+ MiniTest supports code re-use in MiniTest specs already, via a subclass of MiniTest::Spec.
14
+ You might want to look at that option, if you didn't know about it already.
15
+
16
+ == Examples
17
+
18
+ MiniTest::Context.define(:operand) do
19
+ before do
20
+ @operand = 40
21
+ end
22
+ end
23
+
24
+ describe "Addition operator" do
25
+ inherit_context :operand
26
+
27
+ it "should perform addition on the operand." do
28
+ @operand = @operand + 10
29
+ @operand.must_equal(50)
30
+ end
31
+ end
32
+
33
+ describe "Subtraction operator" do
34
+ inherit_context :operand
35
+
36
+ it "should perform subtraction on the operand." do
37
+ @operand = @operand - 10
38
+ @operand.must_equal(30)
39
+ end
40
+ end
41
+
42
+ == Install
43
+
44
+ gem install minitest-context
45
+
46
+ == License
47
+
48
+ See LICENSE.txt
49
+
50
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ desc "Run tests."
2
+ task :test do
3
+ $LOAD_PATH.unshift *%w(./lib ./spec)
4
+ Dir["./spec/*_spec.rb"].each { |f| require(f) }
5
+ end
6
+
7
+ task :default => :test
@@ -0,0 +1,41 @@
1
+ require 'minitest/ext/spec'
2
+
3
+ module MiniTest::Context
4
+
5
+ autoload :VERSION, "minitest/context/version"
6
+
7
+ class << self
8
+
9
+ # @private
10
+ attr_reader :list
11
+
12
+ # Define a context for re-use in a subclass of MiniTest::Spec.
13
+ #
14
+ # @example
15
+ #
16
+ # MiniTest::Context.define(:example) do
17
+ # before do
18
+ # puts "Hello, world!"
19
+ # end
20
+ # end
21
+ #
22
+ # @param [Symbol] name
23
+ # The name of the context to define.
24
+ #
25
+ # @param [Proc] block
26
+ # A Proc object that is evaluated in a subclass of MiniTest::Spec
27
+ # through {MiniTest::Spec.inherit_context inherit_context}.
28
+ #
29
+ # @raise [ArgumentError]
30
+ # Raises an ArgumentError if _block_ is not supplied as an argument.
31
+ #
32
+ # @return [void]
33
+ def define name, &block
34
+ raise ArgumentError, "Block expected." unless block_given?
35
+ @list ||= Hash.new { |h,k| h[k] = [] }
36
+ @list[name] << block
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,5 @@
1
+ module MiniTest
2
+ module Context
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ class MiniTest::Spec
2
+
3
+ class << self
4
+
5
+ # Evaluates a context by _name_ in the scope of a MiniTest::Spec subclass.
6
+ #
7
+ # @example
8
+ #
9
+ # describe ExampleClass do
10
+ # inherit_context :example
11
+ # end
12
+ #
13
+ # @param [Symbol] name
14
+ # The name of a context which has been defined by {MiniTest::Context.define define}.
15
+ #
16
+ # @raise [ArgumentError]
17
+ # Raises an ArgumentError if a context by _name_ does not exist.
18
+ #
19
+ # @return [void]
20
+ def inherit_context name
21
+ if MiniTest::Context.list.has_key?(name)
22
+ MiniTest::Context.list[name].each do |context|
23
+ class_eval &context
24
+ end
25
+ else
26
+ raise ArgumentError, "No context with #{name} found."
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "minitest/context/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "minitest-context"
7
+ s.version = MiniTest::Context::VERSION
8
+ s.authors = ["robgleeson"]
9
+ s.email = ["rob@flowof.info"]
10
+ s.homepage = "https://github.com/robgleeson/minitest-context"
11
+
12
+ s.summary = "Defines contexts for code reuse in MiniTest specs that share common expectations."
13
+ s.description = s.summary
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_runtime_dependency "minitest", "~> 2.5"
21
+ s.add_development_dependency "rake" , "~> 0.9.2"
22
+ end
@@ -0,0 +1,5 @@
1
+ MiniTest::Context.define(:before_block) do
2
+ before do
3
+ @example = [1,2,3]
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ MiniTest::Context.define(:stacked_context) do
2
+ before do
3
+ @number ||= 1
4
+ end
5
+ end
6
+
7
+ MiniTest::Context.define(:stacked_context) do
8
+ before do
9
+ @number += 1
10
+ end
11
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Contexts" do
4
+ describe "an inherited context." do
5
+ inherit_context :before_block
6
+
7
+ it "should execute a before block and assign an Array to @example." do
8
+ @example.must_be_instance_of(Array)
9
+ end
10
+ end
11
+
12
+ describe "two suites who inherit the same context." do
13
+ inherit_context :before_block
14
+
15
+ describe "Suite 1" do
16
+ it "should inherit context from the parent suite." do
17
+ @example.must_be_instance_of(Array)
18
+ end
19
+ end
20
+
21
+ describe "Suite 2" do
22
+ it "should inherit context from the parent suite." do
23
+ @example.must_be_instance_of(Array)
24
+ end
25
+ end
26
+ end
27
+
28
+ describe "A stacked context." do
29
+ inherit_context :stacked_context
30
+
31
+ it "should execute all stacked contexts." do
32
+ @number.must_equal(2)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "MiniTest::Context.define" do
38
+ it "should raise an ArgumentError when no block is recieved." do
39
+ proc { MiniTest::Context.define(:fail) }.must_raise(ArgumentError)
40
+ end
41
+ end
42
+
43
+ describe "MiniTest::Spec.inherit_context" do
44
+ it "should raise an ArgumentError when no context by given name can be found." do
45
+ proc { MiniTest::Spec.inherit_context(:fail) }.must_raise(ArgumentError)
46
+ end
47
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/spec'
3
+ require 'minitest/context'
4
+ require 'minitest/autorun'
5
+
6
+ Dir["./spec/contexts/*.rb"].each { |f| require(f) }
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-context
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - robgleeson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-15 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: minitest
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 9
30
+ segments:
31
+ - 2
32
+ - 5
33
+ version: "2.5"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 63
45
+ segments:
46
+ - 0
47
+ - 9
48
+ - 2
49
+ version: 0.9.2
50
+ type: :development
51
+ version_requirements: *id002
52
+ description: Defines contexts for code reuse in MiniTest specs that share common expectations.
53
+ email:
54
+ - rob@flowof.info
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - .yardopts
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.txt
68
+ - Rakefile
69
+ - lib/minitest/context.rb
70
+ - lib/minitest/context/version.rb
71
+ - lib/minitest/ext/spec.rb
72
+ - minitest-context.gemspec
73
+ - spec/contexts/before_block_context.rb
74
+ - spec/contexts/stacked_context.rb
75
+ - spec/minitest_context_spec.rb
76
+ - spec/spec_helper.rb
77
+ has_rdoc: true
78
+ homepage: https://github.com/robgleeson/minitest-context
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options: []
83
+
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.6.2
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Defines contexts for code reuse in MiniTest specs that share common expectations.
111
+ test_files:
112
+ - spec/contexts/before_block_context.rb
113
+ - spec/contexts/stacked_context.rb
114
+ - spec/minitest_context_spec.rb
115
+ - spec/spec_helper.rb