rspec-given 2.4.4 → 3.0.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.
- checksums.yaml +4 -4
- data/Gemfile +5 -2
- data/Gemfile.lock +6 -10
- data/README.md +223 -73
- data/README.old +226 -76
- data/Rakefile +26 -17
- data/TODO +13 -0
- data/examples/example_helper.rb +8 -1
- data/examples/integration/and_spec.rb +6 -11
- data/examples/integration/focused_line_spec.rb +2 -1
- data/examples/integration/given_spec.rb +19 -9
- data/examples/integration/invariant_spec.rb +6 -6
- data/examples/integration/then_spec.rb +0 -1
- data/examples/loader.rb +3 -0
- data/examples/minitest/assert_raises_spec.rb +25 -0
- data/examples/minitest_helper.rb +38 -0
- data/examples/stack/stack_spec.rb +2 -3
- data/lib/given.rb +2 -0
- data/lib/rspec/given.rb +1 -19
- 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/spec/lib/given/binary_operation_spec.rb +19 -0
- data/spec/lib/{rspec/given → given}/evaluator_spec.rb +4 -1
- data/spec/lib/{rspec/given → given}/ext/numeric_spec.rb +2 -2
- data/spec/lib/{rspec/given → given}/extensions_spec.rb +2 -2
- data/spec/lib/given/failure_matcher_spec.rb +83 -0
- data/spec/lib/given/failure_spec.rb +49 -0
- data/spec/lib/given/file_cache_spec.rb +26 -0
- data/spec/lib/{rspec/given → given}/fuzzy_number_spec.rb +2 -2
- data/spec/lib/{rspec/given → given}/have_failed_spec.rb +5 -4
- data/spec/lib/given/line_extractor_spec.rb +84 -0
- data/spec/lib/{rspec/given → given}/module_methods_spec.rb +2 -2
- data/spec/lib/{rspec/given → given}/natural_assertion_spec.rb +4 -36
- data/spec/lib/{rspec/given → given}/options_spec.rb +33 -33
- data/spec/spec_helper.rb +20 -0
- data/spec/support/faux_then.rb +2 -2
- data/spec/support/natural_assertion_control.rb +1 -1
- metadata +34 -41
- data/README +0 -679
- data/examples/integration/failing_spec.rb +0 -5
- data/lib/rspec/given/configure.rb +0 -20
- data/lib/rspec/given/core.rb +0 -9
- data/lib/rspec/given/evaluator.rb +0 -39
- data/lib/rspec/given/ext/numeric.rb +0 -32
- data/lib/rspec/given/extensions.rb +0 -262
- data/lib/rspec/given/failure.rb +0 -53
- data/lib/rspec/given/file_cache.rb +0 -19
- data/lib/rspec/given/fuzzy_number.rb +0 -70
- data/lib/rspec/given/fuzzy_shortcuts.rb +0 -1
- data/lib/rspec/given/have_failed.rb +0 -77
- data/lib/rspec/given/line_extractor.rb +0 -43
- data/lib/rspec/given/module_methods.rb +0 -70
- data/lib/rspec/given/monkey.rb +0 -41
- data/lib/rspec/given/natural_assertion.rb +0 -193
- data/lib/rspec/given/rspec1_given.rb +0 -11
- data/lib/rspec/given/version.rb +0 -10
- data/spec/lib/rspec/given/failure_spec.rb +0 -17
- data/spec/lib/rspec/given/file_cache_spec.rb +0 -28
- data/spec/lib/rspec/given/line_extractor_spec.rb +0 -86
- /data/spec/lib/{rspec/given → given}/ext/numeric_specifications.rb +0 -0
- /data/spec/lib/{rspec/given → given}/lexical_purity_spec.rb +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'example_helper'
|
|
2
2
|
|
|
3
3
|
describe "Running Givens before Whens" do
|
|
4
4
|
Given(:info) { [] }
|
|
@@ -11,11 +11,19 @@ describe "Running Givens before Whens" do
|
|
|
11
11
|
context "inner with When" do
|
|
12
12
|
Given { info << "inner1" }
|
|
13
13
|
Given { info << "inner2" }
|
|
14
|
-
Then {
|
|
14
|
+
Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when"], info }
|
|
15
15
|
|
|
16
16
|
context "using a nested When" do
|
|
17
17
|
When { info << "when2" }
|
|
18
|
-
Then {
|
|
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
|
+
}
|
|
19
27
|
end
|
|
20
28
|
end
|
|
21
29
|
end
|
|
@@ -26,27 +34,29 @@ describe "Running Givens before Whens" do
|
|
|
26
34
|
context "inner with when" do
|
|
27
35
|
Given { info << "inner1" }
|
|
28
36
|
Given { info << "inner2" }
|
|
29
|
-
Then {
|
|
37
|
+
Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when"], info }
|
|
30
38
|
end
|
|
31
39
|
end
|
|
32
40
|
|
|
33
41
|
context "using no whens" do
|
|
34
42
|
Given { info << "inner1" }
|
|
35
43
|
Given { info << "inner2" }
|
|
36
|
-
Then {
|
|
44
|
+
Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2"], info }
|
|
37
45
|
end
|
|
38
46
|
end
|
|
39
47
|
|
|
40
48
|
describe "Lazy Givens" do
|
|
41
|
-
Given(:bomb) { fail "SHOULD NEVER BE CALLED" }
|
|
49
|
+
Given(:bomb) { fail StandardError, "SHOULD NEVER BE CALLED" }
|
|
42
50
|
|
|
43
51
|
context "when called" do
|
|
44
|
-
Then {
|
|
52
|
+
Then {
|
|
53
|
+
given_assert_raises(StandardError, /NEVER/) { bomb }
|
|
54
|
+
}
|
|
45
55
|
end
|
|
46
56
|
|
|
47
57
|
context "when not called" do
|
|
48
58
|
Given(:value) { :ok }
|
|
49
|
-
Then {
|
|
59
|
+
Then { given_assert_equal :ok, value }
|
|
50
60
|
end
|
|
51
61
|
end
|
|
52
62
|
|
|
@@ -57,7 +67,7 @@ describe "Non-Lazy Givens" do
|
|
|
57
67
|
|
|
58
68
|
context "inner" do
|
|
59
69
|
Given!(:a) { info << :given; "A VALUE" }
|
|
60
|
-
Then {
|
|
70
|
+
Then { given_assert_equal [:given, :when], info }
|
|
61
71
|
end
|
|
62
72
|
|
|
63
73
|
end
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'example_helper'
|
|
2
2
|
|
|
3
3
|
describe "Invariants" do
|
|
4
4
|
Given(:info) { [] }
|
|
5
5
|
|
|
6
6
|
Invariant { info << "I1" }
|
|
7
7
|
|
|
8
|
-
Then {
|
|
8
|
+
Then { given_assert_equal ["I1"], info }
|
|
9
9
|
|
|
10
10
|
context "with nested invariants" do
|
|
11
11
|
Invariant { info << "I2" }
|
|
12
12
|
|
|
13
|
-
Then {
|
|
13
|
+
Then { given_assert_equal ["I1", "I2"], info }
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
context "with multiple invariants" do
|
|
17
17
|
Invariant { info << "I2a" }
|
|
18
18
|
Invariant { info << "I2b" }
|
|
19
19
|
|
|
20
|
-
Then {
|
|
20
|
+
Then { given_assert_equal ["I1", "I2a", "I2b"], info }
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
context "with a when" do
|
|
@@ -25,7 +25,7 @@ describe "Invariants" do
|
|
|
25
25
|
|
|
26
26
|
When(:when_info) { info.dup }
|
|
27
27
|
|
|
28
|
-
Then {
|
|
29
|
-
Then {
|
|
28
|
+
Then { given_assert_equal ["I1", "I2"], info }
|
|
29
|
+
Then { given_assert_equal [], when_info }
|
|
30
30
|
end
|
|
31
31
|
end
|
data/examples/loader.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'minitest/given'
|
|
2
|
+
require 'minitest/autorun'
|
|
3
|
+
|
|
4
|
+
describe "stacks" do
|
|
5
|
+
context "when it fails" do
|
|
6
|
+
When(:result) { fail StandardError, "Oops" }
|
|
7
|
+
|
|
8
|
+
Then { result.must_raise(StandardError, /oops/i) }
|
|
9
|
+
Then {
|
|
10
|
+
assert_raises(StandardError, /oops/i) do
|
|
11
|
+
result.die
|
|
12
|
+
end
|
|
13
|
+
}
|
|
14
|
+
Then { result == Failure() }
|
|
15
|
+
Then { result == Failure(StandardError) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "when it does not fail" do
|
|
19
|
+
When(:result) { :ok }
|
|
20
|
+
|
|
21
|
+
Then { result != Failure() }
|
|
22
|
+
Then { result != Failure(StandardError) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -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
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
require 'rspec/given'
|
|
2
1
|
require 'example_helper'
|
|
3
2
|
require 'stack'
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
Given.use_natural_assertions
|
|
6
5
|
|
|
7
6
|
describe Stack do
|
|
8
7
|
Given(:stack) { Stack.new }
|
|
@@ -24,7 +23,7 @@ describe Stack do
|
|
|
24
23
|
|
|
25
24
|
context "when popping" do
|
|
26
25
|
When(:result) { stack.pop }
|
|
27
|
-
Then { result
|
|
26
|
+
Then { result == Failure(Stack::UnderflowError, /empty/) }
|
|
28
27
|
end
|
|
29
28
|
end
|
|
30
29
|
|
data/lib/given.rb
ADDED
data/lib/rspec/given.rb
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
module Given
|
|
3
|
-
def self.using_old_rspec?
|
|
4
|
-
defined?(Spec) &&
|
|
5
|
-
defined?(Spec::VERSION) &&
|
|
6
|
-
defined?(Spec::VERSION::SUMMARY) &&
|
|
7
|
-
Spec::VERSION::SUMMARY =~ /^rspec +1\./
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
if RSpec::Given.using_old_rspec?
|
|
13
|
-
require 'rspec/given/rspec1_given'
|
|
14
|
-
else
|
|
15
|
-
require 'rspec/given/core'
|
|
16
|
-
require 'rspec/given/have_failed'
|
|
17
|
-
require 'rspec/given/configure'
|
|
18
|
-
require 'rspec/given/monkey'
|
|
19
|
-
end
|
|
1
|
+
require 'given/rspec/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/minitest/**/*").
|
|
22
|
+
exclude("spec/**/*").
|
|
23
|
+
exclude("examples/**/*")
|
|
24
|
+
RSPEC_GIVEN_FILES = FileList[*PKG_FILES].
|
|
25
|
+
exclude("lib/mini*/**/*").
|
|
26
|
+
exclude("lib/minitest-given.rb").
|
|
27
|
+
exclude("lib/given/**/*")
|
|
28
|
+
MINITEST_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
|
+
MINITEST_GIVEN_SPEC = Gem::Specification.new do |s|
|
|
63
|
+
s.name = 'minitest-given'
|
|
64
|
+
s.version = Given::VERSION
|
|
65
|
+
s.summary = "Given/When/Then Specification Extensions for Minitest::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 = MINITEST_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 minitest-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(MINITEST_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 "minitest-given.gemspec" => ["rakelib/gemspec.rake"] do |t|
|
|
139
|
+
require 'yaml'
|
|
140
|
+
open(t.name, "w") { |f| f.puts MINITEST_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", "minitest-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 "MINITEST_GIVEN_FILES=#{MINITEST_GIVEN_FILES.inspect}"
|
|
159
|
+
puts "==============="
|
|
160
|
+
end
|
|
161
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require './rakelib/bundler_fix'
|
|
2
|
+
|
|
3
|
+
METRICS_FILES = FileList['lib/**/*.rb']
|
|
4
|
+
|
|
5
|
+
task :check_flog do
|
|
6
|
+
sh "type flog >/dev/null 2>&1", :verbose => false do |status|
|
|
7
|
+
fail "Install flog to generate complexity metrics" unless status
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
task :check_flay do
|
|
12
|
+
sh "type flay >/dev/null 2>&1", :verbose => false do |status|
|
|
13
|
+
fail "Install flay to generate complexity metrics" unless status
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc "Run complexity metrics"
|
|
18
|
+
task :flog, [:all] => :check_flog do |t, args|
|
|
19
|
+
flags = args.all ? "--all" : ""
|
|
20
|
+
nobundle do
|
|
21
|
+
sh "flog #{flags} #{METRICS_FILES}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc "Run duplication metrics"
|
|
26
|
+
task :flay => :check_flay do
|
|
27
|
+
nobundle do
|
|
28
|
+
sh "flay #{METRICS_FILES}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require './rakelib/bundler_fix'
|
|
2
|
+
|
|
3
|
+
task :check_preview do
|
|
4
|
+
sh "type ghpreview >/dev/null 2>&1", :verbose => false do |status|
|
|
5
|
+
fail "Install ghpreview to generate a local REAMDE preview page" unless status
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc "Generate the GitHub readme locally"
|
|
10
|
+
task :preview => :check_preview do
|
|
11
|
+
nobundle do
|
|
12
|
+
sh "ghpreview #{FileList['README.*']}"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Given::BinaryOperation do
|
|
4
|
+
Given(:binary) { Given::BinaryOperation.parse(sexp) }
|
|
5
|
+
|
|
6
|
+
context "with a valid binary sexp" do
|
|
7
|
+
Given(:sexp) { [:binary, [:@ident, "a"], :==, [:@ident, "b"]] }
|
|
8
|
+
Then { binary.left.should == [:@ident, "a"] }
|
|
9
|
+
Then { binary.operator.should == :== }
|
|
10
|
+
Then { binary.right.should == [:@ident, "b"] }
|
|
11
|
+
Then { binary.explain.should == "to equal" }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "with a non-binary sexp" do
|
|
15
|
+
Given(:sexp) { [:something_else] }
|
|
16
|
+
Then { binary.should be_nil }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "Environmental Access" do
|
|
4
|
+
use_natural_assertions false
|
|
4
5
|
X = 1
|
|
5
6
|
Given(:a) { 2 }
|
|
6
7
|
FauxThen { X + a }
|
|
@@ -14,6 +15,7 @@ end
|
|
|
14
15
|
module Nested
|
|
15
16
|
X = 1
|
|
16
17
|
describe "Environmental Access with Nested modules" do
|
|
18
|
+
use_natural_assertions false
|
|
17
19
|
Given(:a) { 2 }
|
|
18
20
|
FauxThen { X + a }
|
|
19
21
|
Then { block_result.should == 3 }
|
|
@@ -24,8 +26,9 @@ module Nested
|
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
describe "Evaluator with error object" do
|
|
29
|
+
use_natural_assertions false
|
|
27
30
|
FauxThen { 1 }
|
|
28
31
|
When(:result) { ev.eval_string("fail 'XYZ'") }
|
|
29
|
-
Then { result.class.should ==
|
|
32
|
+
Then { result.class.should == Given::EvalErr }
|
|
30
33
|
Then { result.inspect.should == "RuntimeError: XYZ" }
|
|
31
34
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe Given::ClassExtensions do
|
|
4
4
|
let(:trace) { [] }
|
|
5
5
|
|
|
6
6
|
describe "Given with var" do
|
|
@@ -195,7 +195,7 @@ describe "use_natural_assertions" do
|
|
|
195
195
|
|
|
196
196
|
When(:result) { CONTEXT.use_natural_assertions }
|
|
197
197
|
|
|
198
|
-
if
|
|
198
|
+
if ::Given::NATURAL_ASSERTIONS_SUPPORTED
|
|
199
199
|
Then { result.should_not have_failed }
|
|
200
200
|
else
|
|
201
201
|
Then { result.should have_failed(ArgumentError) }
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'given/failure_matcher'
|
|
3
|
+
|
|
4
|
+
module FailureMatcherSpec
|
|
5
|
+
OtherError = Class.new(StandardError)
|
|
6
|
+
CustomError = Class.new(StandardError)
|
|
7
|
+
SubError = Class.new(CustomError)
|
|
8
|
+
NotMetError = RSpec::Expectations::ExpectationNotMetError
|
|
9
|
+
|
|
10
|
+
describe Given::FailureMatcher do
|
|
11
|
+
use_natural_assertions_if_supported
|
|
12
|
+
|
|
13
|
+
Given(:error) { CustomError.new("CUSTOM") }
|
|
14
|
+
|
|
15
|
+
Given(:failure_result) { Given::Failure.new(error) }
|
|
16
|
+
|
|
17
|
+
context "with matching failure results" do
|
|
18
|
+
Then { Failure(CustomError, "CUSTOM").matches?(failure_result) }
|
|
19
|
+
Then { Failure(CustomError, /CUSTOM/).matches?(failure_result) }
|
|
20
|
+
Then { Failure(CustomError).matches?(failure_result) }
|
|
21
|
+
Then { Failure(StandardError).matches?(failure_result) }
|
|
22
|
+
Then { Failure().matches?(failure_result) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "with non-matching results" do
|
|
26
|
+
Then {
|
|
27
|
+
expect {
|
|
28
|
+
Failure(StandardError).matches?(Object.new)
|
|
29
|
+
}.to raise_error(NotMetError,
|
|
30
|
+
/Expected.*StandardError, but nothing failed/)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Then {
|
|
34
|
+
expect {
|
|
35
|
+
Failure(StandardError, /CUSTOM/).matches?(Object.new)
|
|
36
|
+
}.to raise_error(NotMetError,
|
|
37
|
+
/Expected.*StandardError.*matching.*CUSTOM.*, but nothing failed/)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Then {
|
|
41
|
+
expect {
|
|
42
|
+
Failure(StandardError, /OTHER/).matches?(failure_result)
|
|
43
|
+
}.to raise_error(NotMetError,
|
|
44
|
+
/Expected.*StandardError matching.*OTHER.*, but got.*CustomError.*CUSTOM/)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Then {
|
|
48
|
+
expect {
|
|
49
|
+
Failure(OtherError, /CUSTOM/).matches?(failure_result)
|
|
50
|
+
}.to raise_error(NotMetError,
|
|
51
|
+
/Expected.*OtherError matching.*CUSTOM.*, but got.*CustomError.*CUSTOM/)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Then {
|
|
55
|
+
expect {
|
|
56
|
+
Failure(SubError, /CUSTOM/).matches?(failure_result)
|
|
57
|
+
}.to raise_error(NotMetError,
|
|
58
|
+
/Expected.*SubError matching.*CUSTOM.*, but got.*CustomError.*CUSTOM/)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
Then {
|
|
62
|
+
expect {
|
|
63
|
+
Failure(OtherError).matches?(failure_result)
|
|
64
|
+
}.to raise_error(NotMetError,
|
|
65
|
+
/Expected.*OtherError, but got.*CustomError.*CUSTOM/)
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "==" do
|
|
70
|
+
Then { failure_result == Failure() }
|
|
71
|
+
Then { failure_result == Failure(CustomError) }
|
|
72
|
+
Then { Failure() == failure_result }
|
|
73
|
+
Then { Failure(CustomError) == failure_result }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "!=" do
|
|
77
|
+
Then { failure_result != Failure(SubError) }
|
|
78
|
+
Then { Failure(SubError) != failure_result }
|
|
79
|
+
Then { Failure() != nil }
|
|
80
|
+
Then { nil != Failure() }
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'given/failure'
|
|
3
|
+
|
|
4
|
+
describe Given::Failure do
|
|
5
|
+
Given(:other_error) { Class.new(StandardError) }
|
|
6
|
+
Given(:custom_error) { Class.new(StandardError) }
|
|
7
|
+
|
|
8
|
+
Given(:exception) { StandardError.new("Oops") }
|
|
9
|
+
Given(:failure) { Given::Failure.new(exception) }
|
|
10
|
+
|
|
11
|
+
Then { failure.is_a?(Given::Failure).should be_true }
|
|
12
|
+
|
|
13
|
+
describe "general operations" do
|
|
14
|
+
Then { expect { failure.to_s }.to raise_error(StandardError, "Oops") }
|
|
15
|
+
Then { expect { failure.call }.to raise_error(StandardError, "Oops") }
|
|
16
|
+
Then { expect { failure.nil? }.to raise_error(StandardError, "Oops") }
|
|
17
|
+
Then { expect { failure == 0 }.to raise_error(StandardError, "Oops") }
|
|
18
|
+
Then { expect { failure != 0 }.to raise_error(StandardError, "Oops") }
|
|
19
|
+
Then { expect { failure =~ 0 }.to raise_error(StandardError, "Oops") }
|
|
20
|
+
Then { expect { ! failure }.to raise_error(StandardError, "Oops") }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "should raise error" do
|
|
24
|
+
Then { failure.should raise_error(StandardError, "Oops") }
|
|
25
|
+
Then { failure.should raise_error(StandardError) }
|
|
26
|
+
Then { failure.should raise_error }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "== have_failed" do
|
|
30
|
+
use_natural_assertions_if_supported
|
|
31
|
+
Then { failure == have_failed(StandardError, "Oops") }
|
|
32
|
+
Then { failure == have_failed(StandardError) }
|
|
33
|
+
Then { failure == have_failed }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "== Failure" do
|
|
37
|
+
use_natural_assertions_if_supported
|
|
38
|
+
Then { failure == Failure(StandardError, "Oops") }
|
|
39
|
+
Then { failure == Failure(StandardError) }
|
|
40
|
+
Then { failure == Failure() }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "!= Failure" do
|
|
44
|
+
use_natural_assertions_if_supported
|
|
45
|
+
Then { expect { failure != Object.new }.to raise_error(StandardError) }
|
|
46
|
+
Then { failure != Failure(other_error) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|