bacon-expect 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +12 -0
- data/Rakefile +1 -0
- data/bacon-expect.gemspec +22 -0
- data/lib/bacon-expect.rb +9 -0
- data/lib/bacon-expect/bacon_context.rb +4 -0
- data/lib/bacon-expect/expectation.rb +39 -0
- data/lib/bacon-expect/failed_expectation.rb +3 -0
- data/lib/bacon-expect/matchers/be_false.rb +11 -0
- data/lib/bacon-expect/matchers/be_generic.rb +19 -0
- data/lib/bacon-expect/matchers/be_nil.rb +11 -0
- data/lib/bacon-expect/matchers/be_true.rb +11 -0
- data/lib/bacon-expect/matchers/change.rb +29 -0
- data/lib/bacon-expect/matchers/end_with.rb +15 -0
- data/lib/bacon-expect/matchers/eql.rb +15 -0
- data/lib/bacon-expect/matchers/have_generic.rb +19 -0
- data/lib/bacon-expect/matchers/have_items.rb +22 -0
- data/lib/bacon-expect/matchers/include.rb +15 -0
- data/lib/bacon-expect/matchers/match.rb +15 -0
- data/lib/bacon-expect/matchers/match_array.rb +21 -0
- data/lib/bacon-expect/matchers/matchers.rb +78 -0
- data/lib/bacon-expect/matchers/raise_error.rb +31 -0
- data/lib/bacon-expect/matchers/respond_to.rb +28 -0
- data/lib/bacon-expect/matchers/satisfy.rb +15 -0
- data/lib/bacon-expect/matchers/start_with.rb +15 -0
- data/spec_app/.repl_history +0 -0
- data/spec_app/Gemfile +5 -0
- data/spec_app/Rakefile +14 -0
- data/spec_app/app/app_delegate.rb +5 -0
- data/spec_app/resources/Default-568h@2x.png +0 -0
- data/spec_app/spec/helpers/bacon_context.rb +5 -0
- data/spec_app/spec/matchers/be_false_spec.rb +21 -0
- data/spec_app/spec/matchers/be_generic_spec.rb +27 -0
- data/spec_app/spec/matchers/be_nil_spec.rb +17 -0
- data/spec_app/spec/matchers/be_true_spec.rb +21 -0
- data/spec_app/spec/matchers/change_spec.rb +39 -0
- data/spec_app/spec/matchers/end_with_spec.rb +9 -0
- data/spec_app/spec/matchers/eql_spec.rb +19 -0
- data/spec_app/spec/matchers/have_generic_spec.rb +19 -0
- data/spec_app/spec/matchers/have_items_spec.rb +9 -0
- data/spec_app/spec/matchers/include_spec.rb +27 -0
- data/spec_app/spec/matchers/match_array_spec.rb +17 -0
- data/spec_app/spec/matchers/match_spec.rb +17 -0
- data/spec_app/spec/matchers/raise_error_spec.rb +57 -0
- data/spec_app/spec/matchers/respond_to_spec.rb +23 -0
- data/spec_app/spec/matchers/satisfy_spec.rb +13 -0
- data/spec_app/spec/matchers/start_with_spec.rb +9 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 05eb77e0be35a5f75668dea3a280d7c092c0f3af
|
4
|
+
data.tar.gz: ce71a32ac878eada88cf6a9a663c7112e62e7319
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb866f01221e58378e2b17d0b861eefc27bab43271c2b40e6d738c981bc91fd831e190cc8ee26dcce4ab9eed4dffc182a86c9a7558c8b0395a411987505238e5
|
7
|
+
data.tar.gz: 94cd5f2aca9adb79aa019303f6eb99a3319a07462951ca896ab6fefc8091964877c9b712d213a2373b7c29fab66faec49b6be075f2e5e7307420b265764cd40a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ignacio Piantanida
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "bacon-expect"
|
7
|
+
spec.version = "0.1"
|
8
|
+
spec.authors = ["Ignacio Piantanida"]
|
9
|
+
spec.email = ["ijpiantanida@gmail.com"]
|
10
|
+
spec.description = "RSpec's expect syntax in MacBacon"
|
11
|
+
spec.summary = "Bring RSpec 3.0 expect syntax to MacBacon"
|
12
|
+
spec.homepage = "https://github.com/ijpiantanida/bacon-expect"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
data/lib/bacon-expect.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
Motion::Project::App.setup do |app|
|
6
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'bacon-expect/**/*.rb')).reverse.each do |file|
|
7
|
+
app.spec_files << file
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module BaconExpect
|
2
|
+
class Expectation
|
3
|
+
module BaconContext
|
4
|
+
def expect(subject = nil, &block)
|
5
|
+
Expectation.new(subject, &block)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(subject, &subject_block)
|
10
|
+
@subject = subject
|
11
|
+
@subject_block = subject_block
|
12
|
+
end
|
13
|
+
|
14
|
+
def to(matcher)
|
15
|
+
unless matcher.matches?(@subject, &@subject_block)
|
16
|
+
raise matcher.fail!(@subject, &@subject_block)
|
17
|
+
end
|
18
|
+
assert
|
19
|
+
end
|
20
|
+
|
21
|
+
def not_to(matcher)
|
22
|
+
if matcher.matches?(@subject, &@subject_block)
|
23
|
+
raise matcher.fail!(@subject, &@subject_block)
|
24
|
+
end
|
25
|
+
assert
|
26
|
+
end
|
27
|
+
alias_method :to_not, :not_to
|
28
|
+
|
29
|
+
def assert
|
30
|
+
true.should == true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module Spector
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class BeGeneric
|
3
|
+
def initialize(method_name, *args)
|
4
|
+
@method_name = method_name
|
5
|
+
@args = args
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(value)
|
9
|
+
value.send("#{@method_name}?", *@args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def fail!(subject)
|
13
|
+
message = "#{subject} expected to be #{@method_name}"
|
14
|
+
message += " with #{@args}" unless @args.empty?
|
15
|
+
message += " to return true"
|
16
|
+
raise FailedExpectation.new(message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end; end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class Change
|
3
|
+
def initialize(change_block)
|
4
|
+
@change_block = change_block
|
5
|
+
end
|
6
|
+
|
7
|
+
def by(amount)
|
8
|
+
@change_amount = amount
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def matches?(subject, &expectation_block)
|
13
|
+
old_value = @change_block.call
|
14
|
+
expectation_block.call
|
15
|
+
new_value = @change_block.call
|
16
|
+
if @change_amount
|
17
|
+
new_value - @change_amount == old_value
|
18
|
+
else
|
19
|
+
new_value != old_value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def fail!(subject)
|
24
|
+
message = "Block expected to change value"
|
25
|
+
message += " by #{@change_amount}" if @change_amount
|
26
|
+
raise FailedExpectation.new(message)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end; end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class EndWith
|
3
|
+
def initialize(end_string)
|
4
|
+
@end_string = end_string
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(subject)
|
8
|
+
subject[-@end_string.size..-1] == @end_string
|
9
|
+
end
|
10
|
+
|
11
|
+
def fail!(subject)
|
12
|
+
raise FailedExpectation.new("#{subject} expected to end with #{@start_string}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end; end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class Eql
|
3
|
+
def initialize(value)
|
4
|
+
@value = value
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(subject)
|
8
|
+
subject == @value
|
9
|
+
end
|
10
|
+
|
11
|
+
def fail!(subject)
|
12
|
+
raise FailedExpectation.new("#{subject} expected to be == to #{@value}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end; end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class HaveGeneric
|
3
|
+
def initialize(method_name, *args)
|
4
|
+
@method_name = method_name
|
5
|
+
@args = args
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(subject)
|
9
|
+
subject.send("has_#{@method_name}?", *@args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def fail!(subject)
|
13
|
+
message = "#{subject} has_#{@method_name}?"
|
14
|
+
message += " with #{@args}" unless @args.empty?
|
15
|
+
message += " to return true"
|
16
|
+
raise FailedExpectation.new(message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end; end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class HaveItems
|
3
|
+
def initialize(number_of_items)
|
4
|
+
@number_of_items = number_of_items
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(value)
|
8
|
+
value.size == @number_of_items
|
9
|
+
end
|
10
|
+
|
11
|
+
def items
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
alias_method :keys, :items
|
16
|
+
alias_method :values, :items
|
17
|
+
|
18
|
+
def fail!(subject)
|
19
|
+
raise FailedExpectation.new("#{subject} expected to have #{@number_of_items} items")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end; end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class Include
|
3
|
+
def initialize(*values)
|
4
|
+
@values = *values
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(subject)
|
8
|
+
@values.all?{|v| subject.include?(v)}
|
9
|
+
end
|
10
|
+
|
11
|
+
def fail!(subject)
|
12
|
+
raise FailedExpectation.new("\"#{subject}\" expected to include #{@values}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end; end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class Match
|
3
|
+
def initialize(regex)
|
4
|
+
@regex = regex
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(subject)
|
8
|
+
subject.match(@regex)
|
9
|
+
end
|
10
|
+
|
11
|
+
def fail!(subject)
|
12
|
+
raise FailedExpectation.new("\"#{subject}\" expected to match #{@regex}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end; end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class MatchArray
|
3
|
+
def initialize(array)
|
4
|
+
@array = array
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(subject_array)
|
8
|
+
return false unless subject_array.size == @array.size
|
9
|
+
array_copy = subject_array.dup
|
10
|
+
@array.all? do |item|
|
11
|
+
has = array_copy.include?(item)
|
12
|
+
array_copy.delete(item) if has
|
13
|
+
has
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def fail!(subject_array)
|
18
|
+
raise FailedExpectation.new("\"#{subject_array}\" expected to have same items as #{@array}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end; end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module BaconExpect
|
2
|
+
module Matcher
|
3
|
+
module BaconContext
|
4
|
+
def be_nil
|
5
|
+
BeNil.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def be_true
|
9
|
+
BeTrue.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def be_false
|
13
|
+
BeFalse.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def raise_error(exception_class = Exception, message = "")
|
17
|
+
RaiseError.new(exception_class, message)
|
18
|
+
end
|
19
|
+
|
20
|
+
def eql(value)
|
21
|
+
Eql.new(value)
|
22
|
+
end
|
23
|
+
alias_method :be, :eql
|
24
|
+
|
25
|
+
def match(regex)
|
26
|
+
Match.new(regex)
|
27
|
+
end
|
28
|
+
|
29
|
+
def match_array(array)
|
30
|
+
MatchArray.new(array)
|
31
|
+
end
|
32
|
+
alias_method :contain_exactly, :match_array
|
33
|
+
|
34
|
+
def include(*values)
|
35
|
+
Include.new(*values)
|
36
|
+
end
|
37
|
+
|
38
|
+
def have(number)
|
39
|
+
HaveItems.new(number)
|
40
|
+
end
|
41
|
+
|
42
|
+
def satisfy(&block)
|
43
|
+
Satisfy.new(&block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def respond_to(method_name)
|
47
|
+
RespondTo.new(method_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def start_with(substring)
|
51
|
+
StartWith.new(substring)
|
52
|
+
end
|
53
|
+
|
54
|
+
def end_with(substring)
|
55
|
+
EndWith.new(substring)
|
56
|
+
end
|
57
|
+
|
58
|
+
def change(&change_block)
|
59
|
+
Change.new(change_block)
|
60
|
+
end
|
61
|
+
|
62
|
+
def method_missing(method_name, *args, &block)
|
63
|
+
string_method_name = method_name.to_s
|
64
|
+
match_be = string_method_name.match(/^be_(.*)/)
|
65
|
+
if match_be
|
66
|
+
BeGeneric.new(match_be[1], *args)
|
67
|
+
else
|
68
|
+
match_have = string_method_name.match(/^have_(.*)/)
|
69
|
+
if match_have
|
70
|
+
HaveGeneric.new(match_have[1], *args)
|
71
|
+
else
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class RaiseError
|
3
|
+
def initialize(error_class = Exception, message = "")
|
4
|
+
@error_class = error_class.is_a?(Class) ? error_class : Exception
|
5
|
+
@error_message = (error_class.is_a?(String) || error_class.is_a?(Regexp)) ? error_class : message
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(value, &block)
|
9
|
+
begin
|
10
|
+
block.call
|
11
|
+
false
|
12
|
+
rescue Exception => e
|
13
|
+
@rescued_exception = e
|
14
|
+
exception_matches(e)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def exception_matches(e)
|
19
|
+
e.is_a?(@error_class) && (
|
20
|
+
(@error_message.is_a?(String) && e.message.include?(@error_message)) ||
|
21
|
+
(@error_message.is_a?(Regexp) && @error_message.match(e.message))
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def fail!(subject)
|
26
|
+
message = "Block expected to raise exception of type #{@error_class}"
|
27
|
+
message += " but was #{@rescued_exception.class} #{@rescued_exception}" if @rescued_exception
|
28
|
+
raise FailedExpectation.new(message)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end; end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class RespondTo
|
3
|
+
def initialize(method_name)
|
4
|
+
@method_name = method_name
|
5
|
+
end
|
6
|
+
|
7
|
+
def with(number_of_args)
|
8
|
+
@number_of_args = number_of_args
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def arguments
|
13
|
+
self
|
14
|
+
end
|
15
|
+
alias_method :argument, :arguments
|
16
|
+
|
17
|
+
def matches?(subject)
|
18
|
+
valid = true
|
19
|
+
valid &&= subject.respond_to?(@method_name)
|
20
|
+
valid &&= subject.method(@method_name).arity == @number_of_args if valid && @number_of_args
|
21
|
+
valid
|
22
|
+
end
|
23
|
+
|
24
|
+
def fail!(subject)
|
25
|
+
raise FailedExpectation.new("\"#{subject}\" expected to respond_to? #{@method_name}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end; end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class Satisfy
|
3
|
+
def initialize(&condition_block)
|
4
|
+
@condition_block = condition_block
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(*values)
|
8
|
+
@condition_block.call(*values)
|
9
|
+
end
|
10
|
+
|
11
|
+
def fail!(subject)
|
12
|
+
raise FailedExpectation.new("\"#{subject}\" expected to satisfy condition")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end; end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class StartWith
|
3
|
+
def initialize(start_string)
|
4
|
+
@start_string = start_string
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(subject)
|
8
|
+
subject[0...@start_string.size] == @start_string
|
9
|
+
end
|
10
|
+
|
11
|
+
def fail!(subject)
|
12
|
+
raise FailedExpectation.new("#{subject} expected to start with #{@start_string}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end; end
|
File without changes
|
data/spec_app/Gemfile
ADDED
data/spec_app/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$:.unshift("/Library/RubyMotion/lib")
|
3
|
+
require 'motion/project/template/ios'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler'
|
7
|
+
Bundler.require
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
Motion::Project::App.setup do |app|
|
12
|
+
# Use `rake config' to see complete project settings.
|
13
|
+
app.name = 'sample'
|
14
|
+
end
|
Binary file
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe "Matcher::BeFalse" do
|
2
|
+
it 'be_false passes when value is false' do
|
3
|
+
expect(false).to be_false
|
4
|
+
end
|
5
|
+
|
6
|
+
it "be_false fails when value is true" do
|
7
|
+
expect_failure{ expect(true).to be_false }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "be_false fails when value is an Object" do
|
11
|
+
expect_failure{ expect(Object.new).to be_false }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "be_false fails when value is false but asked for not_to" do
|
15
|
+
expect_failure{ expect(false).not_to be_false }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "be_false passes when value is true but asked for not_to" do
|
19
|
+
expect(true).not_to be_false
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe "Matcher::BeGeneric" do
|
2
|
+
it 'be_empty passes when value is empty' do
|
3
|
+
expect([]).to be_empty
|
4
|
+
end
|
5
|
+
|
6
|
+
it "be_empty fails when value is not empty" do
|
7
|
+
expect_failure{ expect([2, 3]).to be_empty }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "be_kind_of passes when value is of the given type" do
|
11
|
+
expect("i'm a string").to be_kind_of(String)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "be_kind_of fails when value is not of the given type" do
|
15
|
+
expect_failure{ expect("i'm a string").to be_kind_of(TrueClass) }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "be_amazing passes when the value responds to amazing? and returns true" do
|
19
|
+
class TestClass; def amazing?; true; end; end
|
20
|
+
expect(TestClass.new).to be_amazing
|
21
|
+
end
|
22
|
+
|
23
|
+
it "be_amazing fails when the value responds to amazing? and returns false" do
|
24
|
+
class TestClass; def amazing?; false; end; end
|
25
|
+
expect_failure{ expect(TestClass.new).to be_amazing }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
describe "Matcher::BeNil" do
|
2
|
+
it 'be_nil passes when value is nil' do
|
3
|
+
expect(nil).to be_nil
|
4
|
+
end
|
5
|
+
|
6
|
+
it "be_nil fails when value is true" do
|
7
|
+
expect_failure{ expect(true).to be_nil }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "be_nil fails when value is false" do
|
11
|
+
expect_failure{ expect(false).to be_nil }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "be_nil fails when value is an Object" do
|
15
|
+
expect_failure{ expect(Object.new).to be_nil }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe "Matcher::BeTrue" do
|
2
|
+
it 'be_true passes when value is true' do
|
3
|
+
expect(true).to be_true
|
4
|
+
end
|
5
|
+
|
6
|
+
it "be_true fails when value is false" do
|
7
|
+
expect_failure{ expect(false).to be_true }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "be_true fails when value is an Object" do
|
11
|
+
expect_failure{ expect(Object.new).to be_true }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "be_true fails when value is true but asked for not_to" do
|
15
|
+
expect_failure{ expect(true).not_to be_true }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "be_true passes when value is false but asked for not_to" do
|
19
|
+
expect(false).to_not be_true
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
describe "Matcher::Change" do
|
2
|
+
class TestClass
|
3
|
+
attr_reader :counter
|
4
|
+
def initialize
|
5
|
+
@counter = 0
|
6
|
+
end
|
7
|
+
|
8
|
+
def add
|
9
|
+
@counter += 1
|
10
|
+
end
|
11
|
+
|
12
|
+
def dont_add; end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'change passes when the expected block changes the result of the argument block' do
|
16
|
+
test_object = TestClass.new
|
17
|
+
expect{ test_object.add }.to change{ test_object.counter }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "change fails when the expected block doesn't change the result of the argument block" do
|
21
|
+
test_object = TestClass.new
|
22
|
+
expect_failure{ expect{ test_object.dont_add }.to change{ test_object.counter } }
|
23
|
+
end
|
24
|
+
|
25
|
+
it "change passes when the expected block doesn't change the result of the argument block but asked not_to" do
|
26
|
+
test_object = TestClass.new
|
27
|
+
expect{ test_object.dont_add }.not_to change{ test_object.counter }
|
28
|
+
end
|
29
|
+
|
30
|
+
it "change when specified 'by' passes when the expected block changes the result of the argument block by the given amount" do
|
31
|
+
test_object = TestClass.new
|
32
|
+
expect{ test_object.add; test_object.add }.to change{ test_object.counter }.by(2)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "change when specified 'by' fails when the expected block changes the result of the argument block by a different amount" do
|
36
|
+
test_object = TestClass.new
|
37
|
+
expect_failure{ expect{ test_object.add; test_object.add }.to change{ test_object.counter }.by(6) }
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe "Matcher::EndWith" do
|
2
|
+
it 'end_with passes when the subject ends with the given string' do
|
3
|
+
expect("super").to end_with("per")
|
4
|
+
end
|
5
|
+
|
6
|
+
it "end_with fails when the subject doesn't end with the given string" do
|
7
|
+
expect_failure{ expect("super").to end_with("key") }
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe "Matcher::Eql" do
|
2
|
+
it 'eql passes when value is == to subject' do
|
3
|
+
obj = Object.new
|
4
|
+
expect(obj).to eql(obj)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "eql fails when value is not == subject" do
|
8
|
+
expect_failure{ expect(Object.new).to eql(Object.new) }
|
9
|
+
end
|
10
|
+
|
11
|
+
it "eql fails when value is nil and subject an Object" do
|
12
|
+
expect_failure{ expect(Object.new).to eql(nil) }
|
13
|
+
end
|
14
|
+
|
15
|
+
it "be is an alias of eql" do
|
16
|
+
obj = Object.new
|
17
|
+
expect(obj).to be(obj)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe "Matcher::HaveGeneric" do
|
2
|
+
it "have_key passes if the hash includes the given key" do
|
3
|
+
expect({a: 1, b: 2, c: 3}).to have_key(:c)
|
4
|
+
end
|
5
|
+
|
6
|
+
it "have_key fails if the hash doesn't include the given key" do
|
7
|
+
expect_failure{ expect({a: 1, b: 2, c: 3}).to have_key(:h) }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "have_color passes when the value responds to has_color? and returns true" do
|
11
|
+
class TestClass; def has_color?(color); color == :red; end; end
|
12
|
+
expect(TestClass.new).to have_color(:red)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "have_color fails when the value responds to has_color? and returns false" do
|
16
|
+
class TestClass; def has_color?(color); color == :red; end; end
|
17
|
+
expect_failure{ expect(TestClass.new).to have_color(:blue) }
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe "Matcher::HaveItems" do
|
2
|
+
it 'have passes when subject has the same number of items' do
|
3
|
+
expect([1,2,3]).to have(3).items
|
4
|
+
end
|
5
|
+
|
6
|
+
it 'have fails when subject has the a different number of items' do
|
7
|
+
expect_failure{ expect([1,2,3]).to have(10).items }
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe "Matcher::Include" do
|
2
|
+
it 'include passes when subject include? responds true' do
|
3
|
+
expect([1,2,3,4]).to include(4)
|
4
|
+
end
|
5
|
+
|
6
|
+
it 'include fails when subject include? responds false' do
|
7
|
+
expect_failure{ expect([1,2,3,4]).to include("asd") }
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'include passes when an object responds true to include?' do
|
11
|
+
class TestClass; def include?(value); true; end; end
|
12
|
+
expect(TestClass.new).to include(3)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'include passes when an object responds false to include?' do
|
16
|
+
class TestClass; def include?(value); false; end; end
|
17
|
+
expect_failure{ expect(TestClass.new).to include(3) }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "include passes when all values are included in subject" do
|
21
|
+
expect([1,2,3,4]).to include(2,3,4)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "include fails when some values are not included in subject" do
|
25
|
+
expect_failure{ expect([1,2,3,4]).to include(2,3,4, 6) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
describe "Matcher::MatchArray" do
|
2
|
+
it 'match_array passes when subject has the same items as value' do
|
3
|
+
expect([1,2,3,4]).to match_array([4,2,1,3])
|
4
|
+
end
|
5
|
+
|
6
|
+
it "match_array fails when subject has less items than value" do
|
7
|
+
expect_failure{ expect([1,2,3]).to match_array([1,2,3,4]) }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "match_array fails when subject has more items than value" do
|
11
|
+
expect_failure{ expect([1,2,3,4]).to match_array([1,2,4,4,3]) }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "match_array fails when subject has different items" do
|
15
|
+
expect_failure{ expect([1,2,3,4]).to match_array([Object.new, "a", 2, 3]) }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
describe "Matcher::Match" do
|
2
|
+
it 'match passes when subject is a string and matches the regex' do
|
3
|
+
expect("asd asd asd").to match(/asd/)
|
4
|
+
end
|
5
|
+
|
6
|
+
it "match fails when subject is a string and doesn't match the regex" do
|
7
|
+
expect_failure{ expect("qwerty qwerty").to match(/asd/) }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "match passes when subject is a regex and matches the given string" do
|
11
|
+
expect(/foo/).to match("food")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "match fails when subject is a regex and doesn't matche the given string" do
|
15
|
+
expect_failure{ expect(/foo/).to match("drink") }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
describe "Matcher::RaiseError" do
|
2
|
+
it 'raise_error without argument passes when the block raises any exception' do
|
3
|
+
expect{ 1/0 }.to raise_error
|
4
|
+
end
|
5
|
+
|
6
|
+
it "raise_error without argument failes when the block doesn't raise any exception" do
|
7
|
+
expect_failure{ expect{ Object.new }.to raise_error }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "raise_error with a class argument passes when the block raises an exception of the argument class" do
|
11
|
+
expect{ 1/0 }.to raise_error(ZeroDivisionError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "raise_error with a class argument fails when the block raises an exception of a different class" do
|
15
|
+
expect_failure{ expect{ 1/0 }.to raise_error(ArgumentError) }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raise_error with a string argument passes when the block raises an exception with a message that includes the string" do
|
19
|
+
expect{ raise "one message" }.to raise_error("one message")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raise_error with a string argument fails when the block raises an exception with a message that doesn't include the string" do
|
23
|
+
expect_failure{ expect{ raise "one message" }.to raise_error("different") }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raise_error with a Regex argument passes when the block raises an exception with a message that matches the Regex" do
|
27
|
+
expect{ raise "one message" }.to raise_error(/message/)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raise_error with a Regex argument fails when the block raises an exception with a message that doesn't match the Regex" do
|
31
|
+
expect_failure{ expect{ raise "one message" }.to raise_error(/different/) }
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raise_error with a class and a string argument passes if the block raises an exception of the same class and includes the string in its message" do
|
35
|
+
expect{ raise ArgumentError.new("with a message") }.to raise_error(ArgumentError, "message")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raise_error with a class and a string argument fails if the block raises an exception of the same class and but doesn't include the string in its message" do
|
39
|
+
expect_failure{ expect{ raise ArgumentError.new("with a message") }.to raise_error(ArgumentError, "different") }
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raise_error with a class and a string argument fails if the block raises an exception of a different class" do
|
43
|
+
expect_failure{ expect{ raise ArgumentError.new("with a message") }.to raise_error(ZeroDivisionError, "message") }
|
44
|
+
end
|
45
|
+
|
46
|
+
it "raise_error with a class and a regex argument passes if the block raises an exception of the same class and includes the string in its message" do
|
47
|
+
expect{ raise ArgumentError.new("with a message") }.to raise_error(ArgumentError, /message/)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "raise_error with a class and a regex argument fails if the block raises an exception of the same class and but doesn't include the string in its message" do
|
51
|
+
expect_failure{ expect{ raise ArgumentError.new("with a message") }.to raise_error(ArgumentError, /different/) }
|
52
|
+
end
|
53
|
+
|
54
|
+
it "raise_error with a class and a regex argument fails if the block raises an exception of a different class" do
|
55
|
+
expect_failure{ expect{ raise ArgumentError.new("with a message") }.to raise_error(ZeroDivisionError, /message/) }
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
describe "Matcher::RespondTo" do
|
2
|
+
it 'respond_to passes when subject responds to method name' do
|
3
|
+
expect("string").to respond_to(:upcase)
|
4
|
+
end
|
5
|
+
|
6
|
+
it "respond_to fails when subject doesn't respond to method name" do
|
7
|
+
expect_failure{ expect("string").to respond_to(:floor) }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "respond_to when given number of arguments fails when subject doesn't respond to method name" do
|
11
|
+
expect_failure{ expect("string").to respond_to(:floor).with(2).arguments }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "respond_to when given number of arguments passes when subject responds to method name with exactly the same number of arguments" do
|
15
|
+
class TestCase; def call_me(a,b,c); end; end
|
16
|
+
expect(TestCase.new).to respond_to(:call_me).with(3).arguments
|
17
|
+
end
|
18
|
+
|
19
|
+
it "respond_to when given number of arguments fails when subject responds to method name with different number of arguments" do
|
20
|
+
class TestCase; def call_me(a,b,c); end; end
|
21
|
+
expect_failure{ expect(TestCase.new).to respond_to(:call_me).with(1).argument }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe "Matcher::Satisfy" do
|
2
|
+
it 'satisfy passes when the block returns true' do
|
3
|
+
expect(1).to satisfy{|v| v == 1}
|
4
|
+
end
|
5
|
+
|
6
|
+
it 'satisfy fails when the block returns false' do
|
7
|
+
expect_failure{ expect(1).to satisfy{|v| v == 3} }
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'satisfy fails when the block raises an exception' do
|
11
|
+
expect{ expect(1).to satisfy{|v| 1/0 } }.to raise_error(ZeroDivisionError)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe "Matcher::StartWith" do
|
2
|
+
it 'start_with passes when the subject starts with the given string' do
|
3
|
+
expect("super").to start_with("sup")
|
4
|
+
end
|
5
|
+
|
6
|
+
it "start_with fails when the subject doesn't start with the given string" do
|
7
|
+
expect_failure{ expect("super").to start_with("key") }
|
8
|
+
end
|
9
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bacon-expect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ignacio Piantanida
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: RSpec's expect syntax in MacBacon
|
42
|
+
email:
|
43
|
+
- ijpiantanida@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bacon-expect.gemspec
|
54
|
+
- lib/bacon-expect.rb
|
55
|
+
- lib/bacon-expect/bacon_context.rb
|
56
|
+
- lib/bacon-expect/expectation.rb
|
57
|
+
- lib/bacon-expect/failed_expectation.rb
|
58
|
+
- lib/bacon-expect/matchers/be_false.rb
|
59
|
+
- lib/bacon-expect/matchers/be_generic.rb
|
60
|
+
- lib/bacon-expect/matchers/be_nil.rb
|
61
|
+
- lib/bacon-expect/matchers/be_true.rb
|
62
|
+
- lib/bacon-expect/matchers/change.rb
|
63
|
+
- lib/bacon-expect/matchers/end_with.rb
|
64
|
+
- lib/bacon-expect/matchers/eql.rb
|
65
|
+
- lib/bacon-expect/matchers/have_generic.rb
|
66
|
+
- lib/bacon-expect/matchers/have_items.rb
|
67
|
+
- lib/bacon-expect/matchers/include.rb
|
68
|
+
- lib/bacon-expect/matchers/match.rb
|
69
|
+
- lib/bacon-expect/matchers/match_array.rb
|
70
|
+
- lib/bacon-expect/matchers/matchers.rb
|
71
|
+
- lib/bacon-expect/matchers/raise_error.rb
|
72
|
+
- lib/bacon-expect/matchers/respond_to.rb
|
73
|
+
- lib/bacon-expect/matchers/satisfy.rb
|
74
|
+
- lib/bacon-expect/matchers/start_with.rb
|
75
|
+
- spec_app/.repl_history
|
76
|
+
- spec_app/Gemfile
|
77
|
+
- spec_app/Rakefile
|
78
|
+
- spec_app/app/app_delegate.rb
|
79
|
+
- spec_app/resources/Default-568h@2x.png
|
80
|
+
- spec_app/spec/helpers/bacon_context.rb
|
81
|
+
- spec_app/spec/matchers/be_false_spec.rb
|
82
|
+
- spec_app/spec/matchers/be_generic_spec.rb
|
83
|
+
- spec_app/spec/matchers/be_nil_spec.rb
|
84
|
+
- spec_app/spec/matchers/be_true_spec.rb
|
85
|
+
- spec_app/spec/matchers/change_spec.rb
|
86
|
+
- spec_app/spec/matchers/end_with_spec.rb
|
87
|
+
- spec_app/spec/matchers/eql_spec.rb
|
88
|
+
- spec_app/spec/matchers/have_generic_spec.rb
|
89
|
+
- spec_app/spec/matchers/have_items_spec.rb
|
90
|
+
- spec_app/spec/matchers/include_spec.rb
|
91
|
+
- spec_app/spec/matchers/match_array_spec.rb
|
92
|
+
- spec_app/spec/matchers/match_spec.rb
|
93
|
+
- spec_app/spec/matchers/raise_error_spec.rb
|
94
|
+
- spec_app/spec/matchers/respond_to_spec.rb
|
95
|
+
- spec_app/spec/matchers/satisfy_spec.rb
|
96
|
+
- spec_app/spec/matchers/start_with_spec.rb
|
97
|
+
homepage: https://github.com/ijpiantanida/bacon-expect
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.1.5
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Bring RSpec 3.0 expect syntax to MacBacon
|
121
|
+
test_files: []
|