given_core 3.0.0.beta.1 → 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 +4 -4
- data/README.md +6 -6
- data/README.old +720 -0
- data/Rakefile +0 -1
- data/lib/given/minispec/all.rb +11 -0
- data/lib/given/minispec/before_extension.rb +36 -0
- data/lib/given/minispec/configure.rb +6 -0
- data/lib/given/minispec/context_extension.rb +3 -0
- data/lib/given/minispec/framework.rb +37 -0
- data/lib/given/minispec/new_assertions.rb +22 -0
- data/lib/given/rspec/all.rb +29 -0
- data/lib/given/rspec/before_extensions.rb +15 -0
- data/lib/given/rspec/configure.rb +19 -0
- data/lib/given/rspec/framework.rb +34 -0
- data/lib/given/rspec/have_failed.rb +37 -0
- data/lib/given/rspec/have_failed_212.rb +30 -0
- data/lib/given/rspec/have_failed_pre212.rb +22 -0
- data/lib/given/rspec/monkey.rb +41 -0
- data/lib/given/rspec/use_natural_assertions.rb +10 -0
- data/lib/given/version.rb +1 -1
- data/rakelib/gemspec.rake +20 -16
- metadata +20 -4
- data/lib/rspec-given.rb +0 -9
data/Rakefile
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'given'
|
3
|
+
|
4
|
+
require 'given/minispec/before_extension'
|
5
|
+
require 'given/minispec/context_extension'
|
6
|
+
require 'given/minispec/framework'
|
7
|
+
require 'given/minispec/configure'
|
8
|
+
|
9
|
+
unless Minitest::Spec.instance_methods.include?(:assertions)
|
10
|
+
require 'given/minispec/new_assertions'
|
11
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
# The before blocks defined in Minitest are inadequate for our use.
|
3
|
+
# This before_extension file allows us to use real before blocks.
|
4
|
+
|
5
|
+
module Minitest
|
6
|
+
class Spec
|
7
|
+
|
8
|
+
# Redefine setup to trigger before chains
|
9
|
+
alias original_setup_without_given setup
|
10
|
+
def setup
|
11
|
+
original_setup_without_given
|
12
|
+
_gvn_establish_befores
|
13
|
+
end
|
14
|
+
|
15
|
+
# Establish the before blocks
|
16
|
+
def _gvn_establish_befores
|
17
|
+
return if defined?(@_gvn_ran_befores) && @_gvn_ran_befores
|
18
|
+
@_gvn_ran_befores = true
|
19
|
+
_gvn_contexts.each do |context|
|
20
|
+
context._Gvn_before_blocks.each do |before_block|
|
21
|
+
instance_eval(&before_block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Lazy accessor for Given's before blocks
|
27
|
+
def self._Gvn_before_blocks
|
28
|
+
@_Gvn_before_blocks ||= []
|
29
|
+
end
|
30
|
+
|
31
|
+
# Define a Given style before block
|
32
|
+
def self._Gvn_before(&block)
|
33
|
+
_Gvn_before_blocks << block
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
module Minitest
|
3
|
+
module Given
|
4
|
+
|
5
|
+
# Framework adapter for Minitest/Given
|
6
|
+
#
|
7
|
+
class Framework
|
8
|
+
def start_evaluation
|
9
|
+
@starting_assertion_count = example.assertions
|
10
|
+
end
|
11
|
+
|
12
|
+
def explicit_assertions?
|
13
|
+
example.assertions > @starting_assertion_count
|
14
|
+
end
|
15
|
+
|
16
|
+
def count_assertion
|
17
|
+
example.assertions += 1
|
18
|
+
end
|
19
|
+
|
20
|
+
def fail_with(*args)
|
21
|
+
raise Minitest::Assertion, args.join(" ")
|
22
|
+
end
|
23
|
+
|
24
|
+
def pending_error
|
25
|
+
Minitest::Skip
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def example
|
31
|
+
Minitest::Spec.current
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Given.framework = Minitest::Given::Framework.new
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
module Minitest
|
3
|
+
module Given
|
4
|
+
|
5
|
+
# If this version of Minitest does not support the #assertions and
|
6
|
+
# #assertions= methods, define a working version of them.
|
7
|
+
#
|
8
|
+
# This allows Minitest/Given to work with Minitest 4.x.
|
9
|
+
#
|
10
|
+
module NewAssertions
|
11
|
+
def assertions
|
12
|
+
_assertions
|
13
|
+
end
|
14
|
+
|
15
|
+
def assertions=(new_value)
|
16
|
+
self._assertions = new_value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Minitest::Spec.__send__(:include, Minitest::Given::NewAssertions)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'given'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Given
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
if Given::NATURAL_ASSERTIONS_SUPPORTED
|
10
|
+
require 'given/rspec/monkey'
|
11
|
+
raise "Unsupported version of RSpec (unable to detect assertions)" unless RSpec::Given::MONKEY
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'given/rspec/have_failed'
|
15
|
+
require 'given/rspec/before_extensions'
|
16
|
+
require 'given/rspec/framework'
|
17
|
+
require 'given/rspec/use_natural_assertions'
|
18
|
+
require 'given/rspec/configure'
|
19
|
+
|
20
|
+
module Given
|
21
|
+
def self.using_old_rspec?
|
22
|
+
defined?(Spec) &&
|
23
|
+
defined?(Spec::VERSION) &&
|
24
|
+
defined?(Spec::VERSION::SUMMARY) &&
|
25
|
+
Spec::VERSION::SUMMARY =~ /^rspec +1\./
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
raise "Unsupported version of RSpec" if Given.using_old_rspec?
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
module RSpec
|
3
|
+
module Given
|
4
|
+
module BeforeHack
|
5
|
+
|
6
|
+
# Some frameworks don't support a robust before block, so we
|
7
|
+
# always use this one. In RSpec, we just delegate to the real
|
8
|
+
# before block handler.
|
9
|
+
def _Gvn_before(*args, &block)
|
10
|
+
before(*args, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rspec/given'
|
3
|
+
|
4
|
+
RSpec.configure do |c|
|
5
|
+
c.extend(Given::ClassExtensions)
|
6
|
+
c.include(Given::InstanceExtensions)
|
7
|
+
c.include(Given::Fuzzy)
|
8
|
+
c.include(Given::FailureMethod)
|
9
|
+
c.extend(RSpec::Given::BeforeHack)
|
10
|
+
c.include(RSpec::Given::HaveFailed)
|
11
|
+
|
12
|
+
if c.respond_to?(:backtrace_exclusion_patterns)
|
13
|
+
c.backtrace_exclusion_patterns << /lib\/rspec\/given/
|
14
|
+
else
|
15
|
+
c.backtrace_clean_patterns << /lib\/rspec\/given/
|
16
|
+
end
|
17
|
+
|
18
|
+
Given.detect_formatters(c)
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
module RSpec
|
3
|
+
module Given
|
4
|
+
|
5
|
+
# Framework interface for RSpec/Given.
|
6
|
+
#
|
7
|
+
class Framework
|
8
|
+
def start_evaluation
|
9
|
+
@matcher_called = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def explicit_assertions?
|
13
|
+
@matcher_called
|
14
|
+
end
|
15
|
+
|
16
|
+
def count_assertion
|
17
|
+
end
|
18
|
+
|
19
|
+
def explicitly_asserted
|
20
|
+
@matcher_called = true
|
21
|
+
end
|
22
|
+
|
23
|
+
def fail_with(*args)
|
24
|
+
::RSpec::Expectations.fail_with(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def pending_error
|
28
|
+
RSpec::Core::Pending::PendingDeclaredInExample
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Given.framework = RSpec::Given::Framework.new
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
# The implementation of RaiseError changed between RSpec 2.11 and 2.12.
|
3
|
+
if RSpec::Matchers::BuiltIn::RaiseError.instance_methods.include?(:does_not_match?)
|
4
|
+
require 'given/rspec/have_failed_212.rb'
|
5
|
+
else
|
6
|
+
require 'given/rspec/have_failed_pre212.rb'
|
7
|
+
end
|
8
|
+
|
9
|
+
module RSpec
|
10
|
+
module Given
|
11
|
+
module HaveFailed
|
12
|
+
|
13
|
+
# Specializes the RaiseError matcher to handle
|
14
|
+
# Failure/non-failure objects.
|
15
|
+
|
16
|
+
# Simular to raise_error(...), but reads a bit better when using
|
17
|
+
# a failure result from a when clause.
|
18
|
+
#
|
19
|
+
# Typical Usage:
|
20
|
+
#
|
21
|
+
# When(:result) { fail "OUCH" }
|
22
|
+
# Then { result.should have_failed(StandardError, /OUCH/) }
|
23
|
+
#
|
24
|
+
# When(:result) { good_code }
|
25
|
+
# Then { result.should_not have_failed }
|
26
|
+
#
|
27
|
+
# :call-seq:
|
28
|
+
# have_failed([exception_class [, message_pattern]])
|
29
|
+
# have_failed([exception_class [, message_pattern]]) { |ex| ... }
|
30
|
+
#
|
31
|
+
def have_failed(error=Exception, message=nil, &block)
|
32
|
+
HaveFailedMatcher.new(error, message, &block)
|
33
|
+
end
|
34
|
+
alias have_raised have_failed
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Given
|
3
|
+
module HaveFailed
|
4
|
+
|
5
|
+
# The RSpec-2.12 and later version of the have_failed matcher
|
6
|
+
|
7
|
+
class HaveFailedMatcher < RSpec::Matchers::BuiltIn::RaiseError
|
8
|
+
def matches?(given_proc, negative_expectation = false)
|
9
|
+
if given_proc.is_a?(::Given::Failure)
|
10
|
+
super
|
11
|
+
else
|
12
|
+
super(lambda { }, negative_expectation)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def does_not_match?(given_proc)
|
17
|
+
if given_proc.is_a?(::Given::Failure)
|
18
|
+
super(given_proc)
|
19
|
+
else
|
20
|
+
super(lambda { })
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
"<Failure matching #{@expected_error}: #{@expected_message.inspect}>"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Given
|
3
|
+
module HaveFailed
|
4
|
+
|
5
|
+
# The Pre-Rspec 2.12 version of the matcher
|
6
|
+
|
7
|
+
class HaveFailedMatcher < RSpec::Matchers::BuiltIn::RaiseError
|
8
|
+
def matches?(given_proc)
|
9
|
+
if given_proc.is_a?(::Given::Failure)
|
10
|
+
super
|
11
|
+
else
|
12
|
+
super(lambda { })
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"<FailureMatcher on #{@expected_error}: #{@expected_message.inspect}>"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'given/module_methods'
|
3
|
+
|
4
|
+
# Monkey patch RSpec to detect matchers used in expectations.
|
5
|
+
|
6
|
+
unless defined?(RSpec::Given::MONKEY)
|
7
|
+
|
8
|
+
if defined?(RSpec::Expectations::PositiveExpectationHandler) &&
|
9
|
+
defined?(RSpec::Expectations::NegativeExpectationHandler)
|
10
|
+
|
11
|
+
RSpec::Given::MONKEY = true
|
12
|
+
|
13
|
+
module RSpec
|
14
|
+
module Expectations
|
15
|
+
class PositiveExpectationHandler
|
16
|
+
class << self
|
17
|
+
alias _gvn_rspec_original_handle_matcher handle_matcher
|
18
|
+
def handle_matcher(actual, matcher, message=nil, &block)
|
19
|
+
::Given.framework.explicitly_asserted
|
20
|
+
_gvn_rspec_original_handle_matcher(actual, matcher, message, &block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class NegativeExpectationHandler
|
26
|
+
class << self
|
27
|
+
alias _gvn_rspec_original_handle_matcher handle_matcher
|
28
|
+
def handle_matcher(actual, matcher, message=nil, &block)
|
29
|
+
::Given.framework.explicitly_asserted
|
30
|
+
_gvn_rspec_original_handle_matcher(actual, matcher, message, &block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
else
|
38
|
+
RSpec::Given::MONKEY = false
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/given/version.rb
CHANGED
data/rakelib/gemspec.rake
CHANGED
@@ -16,16 +16,19 @@ else
|
|
16
16
|
]
|
17
17
|
PKG_FILES.exclude('TAGS')
|
18
18
|
GIVEN_CORE_FILES = FileList[*PKG_FILES].
|
19
|
-
exclude("lib
|
19
|
+
exclude("lib/*-given.rb").
|
20
20
|
exclude("lib/rspec/**/*").
|
21
|
+
exclude("lib/mini*/**/*").
|
21
22
|
exclude("spec/**/*").
|
22
23
|
exclude("examples/**/*")
|
23
24
|
RSPEC_GIVEN_FILES = FileList[*PKG_FILES].
|
24
|
-
exclude("lib/
|
25
|
+
exclude("lib/mini*/**/*").
|
26
|
+
exclude("lib/mini*-given.rb").
|
25
27
|
exclude("lib/given/**/*")
|
26
|
-
|
28
|
+
MINISPEC_GIVEN_FILES = FileList[*PKG_FILES].
|
27
29
|
exclude("spec/**/*").
|
28
|
-
exclude("lib/rspec
|
30
|
+
exclude("lib/rspec-given.rb").
|
31
|
+
exclude("lib/rspec*/**/*").
|
29
32
|
exclude("lib/given/**/*")
|
30
33
|
|
31
34
|
RSPEC_GIVEN_SPEC = Gem::Specification.new do |s|
|
@@ -56,20 +59,20 @@ EOF
|
|
56
59
|
s.rubyforge_project = "given"
|
57
60
|
end
|
58
61
|
|
59
|
-
|
60
|
-
s.name = '
|
62
|
+
MINISPEC_GIVEN_SPEC = Gem::Specification.new do |s|
|
63
|
+
s.name = 'minispec-given'
|
61
64
|
s.version = Given::VERSION
|
62
|
-
s.summary = "Given/When/Then Specification Extensions for
|
65
|
+
s.summary = "Given/When/Then Specification Extensions for Minispec::Spec."
|
63
66
|
s.description = <<EOF
|
64
67
|
Given is a Minitest::Spec extension that allows the use of Given/When/Then
|
65
68
|
terminology when defining specifications.
|
66
69
|
EOF
|
67
|
-
s.files =
|
70
|
+
s.files = MINISPEC_GIVEN_FILES.to_a
|
68
71
|
s.require_path = 'lib' # Use these for libraries.
|
69
72
|
s.rdoc_options = [
|
70
73
|
'--line-numbers', '--inline-source',
|
71
74
|
'--main' , 'doc/main.rdoc',
|
72
|
-
'--title', 'Minitest Given Extensions'
|
75
|
+
'--title', 'Minitest::Spec Given Extensions'
|
73
76
|
]
|
74
77
|
|
75
78
|
s.add_dependency("given_core", "= #{Given::VERSION}")
|
@@ -89,8 +92,9 @@ EOF
|
|
89
92
|
s.version = Given::VERSION
|
90
93
|
s.summary = "Core engine for RSpec::Given and Minitest::Given."
|
91
94
|
s.description = <<EOF
|
92
|
-
|
93
|
-
terminology when defining
|
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.
|
94
98
|
EOF
|
95
99
|
s.files = GIVEN_CORE_FILES.to_a
|
96
100
|
s.require_path = 'lib' # Use these for libraries.
|
@@ -111,7 +115,7 @@ EOF
|
|
111
115
|
s.rubyforge_project = "given"
|
112
116
|
end
|
113
117
|
|
114
|
-
Gem::PackageTask.new(
|
118
|
+
Gem::PackageTask.new(MINISPEC_GIVEN_SPEC) do |pkg|
|
115
119
|
pkg.need_zip = false
|
116
120
|
pkg.need_tar = false
|
117
121
|
end
|
@@ -131,9 +135,9 @@ EOF
|
|
131
135
|
open(t.name, "w") { |f| f.puts RSPEC_GIVEN_SPEC.to_yaml }
|
132
136
|
end
|
133
137
|
|
134
|
-
file "
|
138
|
+
file "minispec-given.gemspec" => ["rakelib/gemspec.rake"] do |t|
|
135
139
|
require 'yaml'
|
136
|
-
open(t.name, "w") { |f| f.puts
|
140
|
+
open(t.name, "w") { |f| f.puts MINISPEC_GIVEN_SPEC.to_yaml }
|
137
141
|
end
|
138
142
|
|
139
143
|
file "given_core.gemspec" => ["rakelib/gemspec.rake"] do |t|
|
@@ -142,7 +146,7 @@ EOF
|
|
142
146
|
end
|
143
147
|
|
144
148
|
desc "Create a stand-alone gemspec"
|
145
|
-
task :gemspec => ["rspec-given.gemspec", "
|
149
|
+
task :gemspec => ["rspec-given.gemspec", "minispec-given.gemspec", "given_core.gemspec"]
|
146
150
|
|
147
151
|
desc "Check Filelists"
|
148
152
|
task :filelists do
|
@@ -151,7 +155,7 @@ EOF
|
|
151
155
|
puts "==============="
|
152
156
|
puts "RSPEC_GIVEN_FILES=#{RSPEC_GIVEN_FILES.inspect}"
|
153
157
|
puts "==============="
|
154
|
-
puts "
|
158
|
+
puts "MINISPEC_GIVEN_FILES=#{MINISPEC_GIVEN_FILES.inspect}"
|
155
159
|
puts "==============="
|
156
160
|
end
|
157
161
|
end
|