expect 0.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 +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +3 -0
- data/LICENSE.md +21 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/VERSION.semver +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/expect.gemspec +22 -0
- data/lib/expect.rb +7 -0
- data/lib/expect/dsl.rb +18 -0
- data/lib/expect/expectation_target.rb +31 -0
- data/lib/expect/matcher.rb +32 -0
- data/lib/expect/matcher/eql.rb +15 -0
- data/lib/expect/matcher/equal.rb +15 -0
- data/lib/expect/matcher/match.rb +15 -0
- data/lib/expect/matcher/raise_exception.rb +21 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 001f1b5fb0806ab92ab77f46da0a66df580ebf64
|
4
|
+
data.tar.gz: 70692c790d9f0e7a549c85127d5c25059b1bb032
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b21b2cbae82afc04e7195fe415febee079a3d4fcae7a635a644c9582edbf5a5e35c45e473bf832db26a2ea8ea99ece33dbe71a8070783d5b91fd09c46c518215
|
7
|
+
data.tar.gz: 7a480b15d6d690202edea292c9eaed0c3cc9a3da3731fd8dd645c726fd128763fc6b65effd095043faab0a0beb671880037ae987f400db9eee41eef1d4e6b6f6
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.0
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Cyril Wack
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Expect
|
2
|
+
|
3
|
+
Expectation library with some built-in matchers for Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'expect'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install expect
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. [Fork it](https://github.com/fixrb/expect/fork)
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/VERSION.semver
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'expect'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/expect.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'expect'
|
3
|
+
spec.version = File.read('VERSION.semver')
|
4
|
+
spec.authors = ['Cyril Wack']
|
5
|
+
spec.email = ['contact@cyril.email']
|
6
|
+
|
7
|
+
# if spec.respond_to?(:metadata)
|
8
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
9
|
+
# end
|
10
|
+
|
11
|
+
spec.summary = 'Expectation library.'
|
12
|
+
spec.description = 'Expectation library with some matchers for Ruby.'
|
13
|
+
spec.homepage = 'https://github.com/fixrb/expect'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
end
|
data/lib/expect.rb
ADDED
data/lib/expect/dsl.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'expectation_target'
|
2
|
+
|
3
|
+
module Expect
|
4
|
+
# Expectation's domain-specific language.
|
5
|
+
module DSL
|
6
|
+
# Expectations are built with this method.
|
7
|
+
#
|
8
|
+
# @api public
|
9
|
+
#
|
10
|
+
# @example Duck example
|
11
|
+
# expect { 42 }.to equal: 42 # => true
|
12
|
+
#
|
13
|
+
# @return [ExpectationTarget] the expectation target.
|
14
|
+
def expect(&input)
|
15
|
+
ExpectationTarget.new(&input)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'matcher'
|
2
|
+
|
3
|
+
module Expect
|
4
|
+
# Wraps the target of an expectation.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# expect { do_something } # => ExpectationTarget wrapping the block
|
8
|
+
class ExpectationTarget < BasicObject
|
9
|
+
def initialize(&actual)
|
10
|
+
@actual = actual
|
11
|
+
end
|
12
|
+
|
13
|
+
# Evaluate to a positive assertion.
|
14
|
+
#
|
15
|
+
# @api public
|
16
|
+
#
|
17
|
+
# @see Matcher#pass?
|
18
|
+
def to(definition)
|
19
|
+
Matcher.pass? false, definition, &@actual
|
20
|
+
end
|
21
|
+
|
22
|
+
# Evaluate to a negative assertion.
|
23
|
+
#
|
24
|
+
# @api public
|
25
|
+
#
|
26
|
+
# @see Matcher#pass?
|
27
|
+
def not_to(definition)
|
28
|
+
Matcher.pass? true, definition, &@actual
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Expect
|
2
|
+
# This module provides matchers to define expectations.
|
3
|
+
module Matcher
|
4
|
+
# Evaluate the expectation with the passed block.
|
5
|
+
#
|
6
|
+
# @param [Boolean] negated
|
7
|
+
# @param [Hash] definition
|
8
|
+
#
|
9
|
+
# @return [Boolean] Report if the expectation is true or false.
|
10
|
+
def self.pass?(negated, definition, &actual)
|
11
|
+
params = Array(definition).flatten 1
|
12
|
+
name = params.first
|
13
|
+
expected_args = params[1..-1]
|
14
|
+
matcher = Matcher.get(name).new(*expected_args)
|
15
|
+
|
16
|
+
negated ^ matcher.matches?(&actual)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get the class of a matcher from its symbol.
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
#
|
23
|
+
# Matcher.get(:eql) # => Eql
|
24
|
+
def self.get(name)
|
25
|
+
const_get name.to_s.split('_').map(&:capitalize).join.to_sym
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Dir[File.join File.dirname(__FILE__), 'matcher', '*.rb'].each do |filename|
|
31
|
+
require_relative filename
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Expect
|
2
|
+
module Matcher
|
3
|
+
# Provides the implementation for `eql`.
|
4
|
+
class Eql < BasicObject
|
5
|
+
def initialize(expected)
|
6
|
+
@expected = expected
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [Boolean] Comparison between actual and expected values.
|
10
|
+
def matches?
|
11
|
+
@expected.eql?(yield)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Expect
|
2
|
+
module Matcher
|
3
|
+
# Provides the implementation for `equal`.
|
4
|
+
class Equal < BasicObject
|
5
|
+
def initialize(expected)
|
6
|
+
@expected = expected
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [Boolean] Comparison between actual and expected values.
|
10
|
+
def matches?
|
11
|
+
@expected.equal? yield
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Expect
|
2
|
+
module Matcher
|
3
|
+
# Provides the implementation for `match`.
|
4
|
+
class Match < BasicObject
|
5
|
+
def initialize(expected)
|
6
|
+
@expected = expected
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [Boolean] Comparison between actual and expected values.
|
10
|
+
def matches?
|
11
|
+
!@expected.match(yield).nil?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Expect
|
2
|
+
module Matcher
|
3
|
+
# Provides the implementation for `raise_exception`.
|
4
|
+
class RaiseException < BasicObject
|
5
|
+
def initialize(expected)
|
6
|
+
@expected = expected
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [Boolean] Comparison between actual and expected values.
|
10
|
+
def matches?
|
11
|
+
begin
|
12
|
+
yield
|
13
|
+
rescue @expected
|
14
|
+
true
|
15
|
+
else
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: expect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cyril Wack
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-10 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.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Expectation library with some matchers for Ruby.
|
42
|
+
email:
|
43
|
+
- contact@cyril.email
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".ruby-version"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.md
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- VERSION.semver
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- expect.gemspec
|
60
|
+
- lib/expect.rb
|
61
|
+
- lib/expect/dsl.rb
|
62
|
+
- lib/expect/expectation_target.rb
|
63
|
+
- lib/expect/matcher.rb
|
64
|
+
- lib/expect/matcher/eql.rb
|
65
|
+
- lib/expect/matcher/equal.rb
|
66
|
+
- lib/expect/matcher/match.rb
|
67
|
+
- lib/expect/matcher/raise_exception.rb
|
68
|
+
homepage: https://github.com/fixrb/expect
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.4.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Expectation library.
|
92
|
+
test_files: []
|
93
|
+
has_rdoc:
|