minispec-given 3.0.0.beta.2
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.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +27 -0
- data/MIT-LICENSE +20 -0
- data/README.md +720 -0
- data/README.old +720 -0
- data/Rakefile +231 -0
- data/TODO +13 -0
- data/doc/main.rdoc +7 -0
- data/examples/example_helper.rb +10 -0
- data/examples/failing/natural_failing_spec.rb +48 -0
- data/examples/failing/sample_spec.rb +7 -0
- data/examples/integration/and_spec.rb +44 -0
- data/examples/integration/failing/eval_subexpression_spec.rb +9 -0
- data/examples/integration/failing/module_nesting_spec.rb +13 -0
- data/examples/integration/failing/undefined_method_spec.rb +9 -0
- data/examples/integration/failing_messages_spec.rb +38 -0
- data/examples/integration/focused_line_spec.rb +9 -0
- data/examples/integration/given_spec.rb +73 -0
- data/examples/integration/invariant_spec.rb +31 -0
- data/examples/integration/then_spec.rb +8 -0
- data/examples/loader.rb +4 -0
- data/examples/minitest_helper.rb +38 -0
- data/examples/other/line_example.rb +9 -0
- data/examples/stack/stack.rb +29 -0
- data/examples/stack/stack_spec.rb +60 -0
- data/examples/stack/stack_spec1.rb +3 -0
- data/lib/given.rb +2 -0
- data/lib/minispec-given.rb +9 -0
- data/lib/minispec/given.rb +1 -0
- data/lib/minitest/given.rb +1 -0
- data/rakelib/bundler_fix.rb +17 -0
- data/rakelib/gemspec.rake +161 -0
- data/rakelib/metrics.rake +30 -0
- data/rakelib/preview.rake +14 -0
- data/test/before_test.rb +22 -0
- data/test/meme_test.rb +36 -0
- metadata +115 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
|
3
|
+
describe "Running Givens before Whens" do
|
4
|
+
Given(:info) { [] }
|
5
|
+
Given { info << "outer1" }
|
6
|
+
Given { info << "outer2" }
|
7
|
+
|
8
|
+
context "using a when without result" do
|
9
|
+
When { info << "when" }
|
10
|
+
|
11
|
+
context "inner with When" do
|
12
|
+
Given { info << "inner1" }
|
13
|
+
Given { info << "inner2" }
|
14
|
+
Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when"], info }
|
15
|
+
|
16
|
+
context "using a nested When" do
|
17
|
+
When { info << "when2" }
|
18
|
+
Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when", "when2"], info}
|
19
|
+
end
|
20
|
+
|
21
|
+
context "using two nested When" do
|
22
|
+
When { info << "when2a" }
|
23
|
+
When { info << "when2b" }
|
24
|
+
Then {
|
25
|
+
given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when", "when2a", "when2b"], info
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "using a when with a result" do
|
32
|
+
When(:result) { info << "when" }
|
33
|
+
|
34
|
+
context "inner with when" do
|
35
|
+
Given { info << "inner1" }
|
36
|
+
Given { info << "inner2" }
|
37
|
+
Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when"], info }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "using no whens" do
|
42
|
+
Given { info << "inner1" }
|
43
|
+
Given { info << "inner2" }
|
44
|
+
Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2"], info }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "Lazy Givens" do
|
49
|
+
Given(:bomb) { fail StandardError, "SHOULD NEVER BE CALLED" }
|
50
|
+
|
51
|
+
context "when called" do
|
52
|
+
Then {
|
53
|
+
given_assert_raises(StandardError, /NEVER/) { bomb }
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when not called" do
|
58
|
+
Given(:value) { :ok }
|
59
|
+
Then { given_assert_equal :ok, value }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "Non-Lazy Givens" do
|
64
|
+
Given(:info) { [] }
|
65
|
+
|
66
|
+
When { info << :when }
|
67
|
+
|
68
|
+
context "inner" do
|
69
|
+
Given!(:a) { info << :given; "A VALUE" }
|
70
|
+
Then { given_assert_equal [:given, :when], info }
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
|
3
|
+
describe "Invariants" do
|
4
|
+
Given(:info) { [] }
|
5
|
+
|
6
|
+
Invariant { info << "I1" }
|
7
|
+
|
8
|
+
Then { given_assert_equal ["I1"], info }
|
9
|
+
|
10
|
+
context "with nested invariants" do
|
11
|
+
Invariant { info << "I2" }
|
12
|
+
|
13
|
+
Then { given_assert_equal ["I1", "I2"], info }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with multiple invariants" do
|
17
|
+
Invariant { info << "I2a" }
|
18
|
+
Invariant { info << "I2b" }
|
19
|
+
|
20
|
+
Then { given_assert_equal ["I1", "I2a", "I2b"], info }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with a when" do
|
24
|
+
Invariant { info << "I2" }
|
25
|
+
|
26
|
+
When(:when_info) { info.dup }
|
27
|
+
|
28
|
+
Then { given_assert_equal ["I1", "I2"], info }
|
29
|
+
Then { given_assert_equal [], when_info }
|
30
|
+
end
|
31
|
+
end
|
data/examples/loader.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
module GivenAssertions
|
3
|
+
def given_assert(cond)
|
4
|
+
assert cond
|
5
|
+
end
|
6
|
+
|
7
|
+
def given_assert_equal(expected, actual)
|
8
|
+
actual.must_equal(expected)
|
9
|
+
end
|
10
|
+
|
11
|
+
def given_assert_match(pattern, actual)
|
12
|
+
actual.must_match(pattern)
|
13
|
+
end
|
14
|
+
|
15
|
+
def given_assert_not_match(pattern, actual)
|
16
|
+
actual.wont_match(pattern)
|
17
|
+
end
|
18
|
+
|
19
|
+
def given_assert_raises(error, pattern=//, &block)
|
20
|
+
ex = assert_raises(error, &block)
|
21
|
+
ex.message.must_match(pattern)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module NaturalAssertionControl
|
26
|
+
def use_natural_assertions_if_supported(enabled=true)
|
27
|
+
if enabled && ! Given::NATURAL_ASSERTIONS_SUPPORTED
|
28
|
+
Given {
|
29
|
+
skip "Natural assertions are not supported in JRuby"
|
30
|
+
}
|
31
|
+
else
|
32
|
+
use_natural_assertions(enabled)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Minitest::Spec.send(:include, GivenAssertions)
|
38
|
+
include NaturalAssertionControl
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Stack
|
2
|
+
class StackError < StandardError; end
|
3
|
+
class UnderflowError < StackError; end
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@items = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def depth
|
10
|
+
@items.size
|
11
|
+
end
|
12
|
+
|
13
|
+
def empty?
|
14
|
+
@items.empty?
|
15
|
+
end
|
16
|
+
|
17
|
+
def top
|
18
|
+
@items.last
|
19
|
+
end
|
20
|
+
|
21
|
+
def push(item)
|
22
|
+
@items << item
|
23
|
+
end
|
24
|
+
|
25
|
+
def pop
|
26
|
+
fail UnderflowError, "Cannot pop an empty stack" if empty?
|
27
|
+
@items.pop
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
require 'stack'
|
3
|
+
|
4
|
+
Given.use_natural_assertions
|
5
|
+
|
6
|
+
describe Stack do
|
7
|
+
Given(:stack) { Stack.new }
|
8
|
+
Given(:initial_contents) { [] }
|
9
|
+
Given { initial_contents.each do |item| stack.push(item) end }
|
10
|
+
|
11
|
+
Invariant { stack.empty? == (stack.depth == 0) }
|
12
|
+
|
13
|
+
context "with an empty stack" do
|
14
|
+
Given(:initial_contents) { [] }
|
15
|
+
Then { stack.depth == 0 }
|
16
|
+
|
17
|
+
context "when pushing" do
|
18
|
+
When { stack.push(:an_item) }
|
19
|
+
|
20
|
+
Then { stack.depth == 1 }
|
21
|
+
Then { stack.top == :an_item }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when popping" do
|
25
|
+
When(:result) { stack.pop }
|
26
|
+
Then { result == Failure(Stack::UnderflowError, /empty/) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with one item" do
|
31
|
+
Given(:initial_contents) { [:an_item] }
|
32
|
+
|
33
|
+
context "when popping" do
|
34
|
+
When(:pop_result) { stack.pop }
|
35
|
+
|
36
|
+
Then { pop_result == :an_item }
|
37
|
+
Then { stack.depth == 0 }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with several items" do
|
42
|
+
Given(:initial_contents) { [:second_item, :top_item] }
|
43
|
+
Given!(:original_depth) { stack.depth }
|
44
|
+
|
45
|
+
context "when pushing" do
|
46
|
+
When { stack.push(:new_item) }
|
47
|
+
|
48
|
+
Then { stack.top == :new_item }
|
49
|
+
Then { stack.depth == original_depth + 1 }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when popping" do
|
53
|
+
When(:pop_result) { stack.pop }
|
54
|
+
|
55
|
+
Then { pop_result == :top_item }
|
56
|
+
Then { stack.top == :second_item }
|
57
|
+
Then { stack.depth == original_depth - 1 }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/given.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'given/minispec/all'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'given/minispec/all'
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'rubygems/package_task'
|
2
|
+
require './lib/given/version'
|
3
|
+
|
4
|
+
if ! defined?(Gem)
|
5
|
+
puts "Package Target requires RubyGEMs"
|
6
|
+
else
|
7
|
+
PKG_FILES = FileList[
|
8
|
+
'[A-Z]*',
|
9
|
+
'lib/*.rb',
|
10
|
+
'lib/**/*.rb',
|
11
|
+
'rakelib/**/*',
|
12
|
+
'test/**/*.rb',
|
13
|
+
'spec/**/*.rb',
|
14
|
+
'examples/**/*',
|
15
|
+
'doc/**/*',
|
16
|
+
]
|
17
|
+
PKG_FILES.exclude('TAGS')
|
18
|
+
GIVEN_CORE_FILES = FileList[*PKG_FILES].
|
19
|
+
exclude("lib/*-given.rb").
|
20
|
+
exclude("lib/rspec/**/*").
|
21
|
+
exclude("lib/mini*/**/*").
|
22
|
+
exclude("spec/**/*").
|
23
|
+
exclude("examples/**/*")
|
24
|
+
RSPEC_GIVEN_FILES = FileList[*PKG_FILES].
|
25
|
+
exclude("lib/mini*/**/*").
|
26
|
+
exclude("lib/mini*-given.rb").
|
27
|
+
exclude("lib/given/**/*")
|
28
|
+
MINISPEC_GIVEN_FILES = FileList[*PKG_FILES].
|
29
|
+
exclude("spec/**/*").
|
30
|
+
exclude("lib/rspec-given.rb").
|
31
|
+
exclude("lib/rspec*/**/*").
|
32
|
+
exclude("lib/given/**/*")
|
33
|
+
|
34
|
+
RSPEC_GIVEN_SPEC = Gem::Specification.new do |s|
|
35
|
+
s.name = 'rspec-given'
|
36
|
+
s.version = Given::VERSION
|
37
|
+
s.summary = "Given/When/Then Specification Extensions for RSpec."
|
38
|
+
s.description = <<EOF
|
39
|
+
Given is an RSpec extension that allows the use of Given/When/Then
|
40
|
+
terminology when defining specifications.
|
41
|
+
EOF
|
42
|
+
s.files = RSPEC_GIVEN_FILES.to_a
|
43
|
+
s.require_path = 'lib' # Use these for libraries.
|
44
|
+
s.rdoc_options = [
|
45
|
+
'--line-numbers', '--inline-source',
|
46
|
+
'--main' , 'doc/main.rdoc',
|
47
|
+
'--title', 'RSpec Given Extensions'
|
48
|
+
]
|
49
|
+
|
50
|
+
s.add_dependency("given_core", "= #{Given::VERSION}")
|
51
|
+
s.add_dependency("rspec", ">= 2.12")
|
52
|
+
|
53
|
+
s.required_ruby_version = '>= 1.9.2'
|
54
|
+
s.license = "MIT"
|
55
|
+
|
56
|
+
s.author = "Jim Weirich"
|
57
|
+
s.email = "jim.weirich@gmail.com"
|
58
|
+
s.homepage = "http://github.com/jimweirich/rspec-given"
|
59
|
+
s.rubyforge_project = "given"
|
60
|
+
end
|
61
|
+
|
62
|
+
MINISPEC_GIVEN_SPEC = Gem::Specification.new do |s|
|
63
|
+
s.name = 'minispec-given'
|
64
|
+
s.version = Given::VERSION
|
65
|
+
s.summary = "Given/When/Then Specification Extensions for Minispec::Spec."
|
66
|
+
s.description = <<EOF
|
67
|
+
Given is a Minitest::Spec extension that allows the use of Given/When/Then
|
68
|
+
terminology when defining specifications.
|
69
|
+
EOF
|
70
|
+
s.files = MINISPEC_GIVEN_FILES.to_a
|
71
|
+
s.require_path = 'lib' # Use these for libraries.
|
72
|
+
s.rdoc_options = [
|
73
|
+
'--line-numbers', '--inline-source',
|
74
|
+
'--main' , 'doc/main.rdoc',
|
75
|
+
'--title', 'Minitest::Spec Given Extensions'
|
76
|
+
]
|
77
|
+
|
78
|
+
s.add_dependency("given_core", "= #{Given::VERSION}")
|
79
|
+
s.add_dependency("minitest", "> 4.3")
|
80
|
+
|
81
|
+
s.required_ruby_version = '>= 1.9.2'
|
82
|
+
s.license = "MIT"
|
83
|
+
|
84
|
+
s.author = "Jim Weirich"
|
85
|
+
s.email = "jim.weirich@gmail.com"
|
86
|
+
s.homepage = "http://github.com/jimweirich/rspec-given"
|
87
|
+
s.rubyforge_project = "given"
|
88
|
+
end
|
89
|
+
|
90
|
+
GIVEN_CORE_SPEC = Gem::Specification.new do |s|
|
91
|
+
s.name = 'given_core'
|
92
|
+
s.version = Given::VERSION
|
93
|
+
s.summary = "Core engine for RSpec::Given and Minitest::Given."
|
94
|
+
s.description = <<EOF
|
95
|
+
Given_core is the basic functionality behind rspec-given and minispec-given,
|
96
|
+
extensions that allow the use of Given/When/Then terminology when defining
|
97
|
+
specifications.
|
98
|
+
EOF
|
99
|
+
s.files = GIVEN_CORE_FILES.to_a
|
100
|
+
s.require_path = 'lib' # Use these for libraries.
|
101
|
+
s.rdoc_options = [
|
102
|
+
'--line-numbers', '--inline-source',
|
103
|
+
'--main' , 'doc/main.rdoc',
|
104
|
+
'--title', 'RSpec Given Extensions'
|
105
|
+
]
|
106
|
+
|
107
|
+
s.add_dependency("sorcerer", ">= 0.3.7")
|
108
|
+
|
109
|
+
s.required_ruby_version = '>= 1.9.2'
|
110
|
+
s.license = "MIT"
|
111
|
+
|
112
|
+
s.author = "Jim Weirich"
|
113
|
+
s.email = "jim.weirich@gmail.com"
|
114
|
+
s.homepage = "http://github.com/jimweirich/rspec-given"
|
115
|
+
s.rubyforge_project = "given"
|
116
|
+
end
|
117
|
+
|
118
|
+
Gem::PackageTask.new(MINISPEC_GIVEN_SPEC) do |pkg|
|
119
|
+
pkg.need_zip = false
|
120
|
+
pkg.need_tar = false
|
121
|
+
end
|
122
|
+
|
123
|
+
Gem::PackageTask.new(RSPEC_GIVEN_SPEC) do |pkg|
|
124
|
+
pkg.need_zip = false
|
125
|
+
pkg.need_tar = false
|
126
|
+
end
|
127
|
+
|
128
|
+
Gem::PackageTask.new(GIVEN_CORE_SPEC) do |pkg|
|
129
|
+
pkg.need_zip = false
|
130
|
+
pkg.need_tar = false
|
131
|
+
end
|
132
|
+
|
133
|
+
file "rspec-given.gemspec" => ["rakelib/gemspec.rake"] do |t|
|
134
|
+
require 'yaml'
|
135
|
+
open(t.name, "w") { |f| f.puts RSPEC_GIVEN_SPEC.to_yaml }
|
136
|
+
end
|
137
|
+
|
138
|
+
file "minispec-given.gemspec" => ["rakelib/gemspec.rake"] do |t|
|
139
|
+
require 'yaml'
|
140
|
+
open(t.name, "w") { |f| f.puts MINISPEC_GIVEN_SPEC.to_yaml }
|
141
|
+
end
|
142
|
+
|
143
|
+
file "given_core.gemspec" => ["rakelib/gemspec.rake"] do |t|
|
144
|
+
require 'yaml'
|
145
|
+
open(t.name, "w") { |f| f.puts GIVEN_CORE_SPEC.to_yaml }
|
146
|
+
end
|
147
|
+
|
148
|
+
desc "Create a stand-alone gemspec"
|
149
|
+
task :gemspec => ["rspec-given.gemspec", "minispec-given.gemspec", "given_core.gemspec"]
|
150
|
+
|
151
|
+
desc "Check Filelists"
|
152
|
+
task :filelists do
|
153
|
+
puts "==============="
|
154
|
+
puts "GIVEN_CORE_FILES=#{GIVEN_CORE_FILES.inspect}"
|
155
|
+
puts "==============="
|
156
|
+
puts "RSPEC_GIVEN_FILES=#{RSPEC_GIVEN_FILES.inspect}"
|
157
|
+
puts "==============="
|
158
|
+
puts "MINISPEC_GIVEN_FILES=#{MINISPEC_GIVEN_FILES.inspect}"
|
159
|
+
puts "==============="
|
160
|
+
end
|
161
|
+
end
|