ndlib-on-rspec 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE +14 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/ndlib-on-rspec.rb +6 -0
- data/lib/ndlib-on-rspec/alias_from_matcher.rb +36 -0
- data/lib/ndlib-on-rspec/delegate_matcher.rb +33 -0
- data/lib/ndlib-on-rspec/version.rb +3 -0
- data/ndlib-on-rspec.gemspec +23 -0
- data/spec/ndlib-on-rspec/alias_from_matcher_spec.rb +37 -0
- data/spec/ndlib-on-rspec/delegate_matcher_spec.rb +38 -0
- data/spec/spec_helper.rb +54 -0
- metadata +79 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
##########################################################################
|
2
|
+
# Copyright 2012 University of Notre Dame
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Ndlib::On::Rspec
|
2
|
+
|
3
|
+
Some Rspec matchers to share across projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ndlib-on-rspec'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ndlib-on-rspec
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Take a look at the /spec directory.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# RSpec matcher to spec alias.
|
2
|
+
RSpec::Matchers.define :alias_from do |method_name|
|
3
|
+
match do |object|
|
4
|
+
@method_name = method_name
|
5
|
+
@object = object
|
6
|
+
if !@object.respond_to?(@method_name)
|
7
|
+
raise "#{@object} does not respond to ##{@method_name}!"
|
8
|
+
end
|
9
|
+
|
10
|
+
# If :alias_method was used
|
11
|
+
returning_value = (@object.method(@to) == @object.method(@method_name))
|
12
|
+
|
13
|
+
# Try something comparing return values
|
14
|
+
if !returning_value
|
15
|
+
@from_returned_value = double('receiver')
|
16
|
+
@object.stub(@method_name).and_return(@from_returned_value)
|
17
|
+
returning_value = (@object.send(@to) == @from_returned_value)
|
18
|
+
end
|
19
|
+
|
20
|
+
returning_value
|
21
|
+
end
|
22
|
+
|
23
|
+
description do
|
24
|
+
"alias ##{@method_name} to ##{@to}"
|
25
|
+
end
|
26
|
+
|
27
|
+
failure_message_for_should do |text|
|
28
|
+
"expected #{@object} to alias ##{@method_name} to ##{@to}"
|
29
|
+
end
|
30
|
+
|
31
|
+
failure_message_for_should_not do |text|
|
32
|
+
"expected #{@object} NOT to alias ##{@method_name} to ##{@to}"
|
33
|
+
end
|
34
|
+
|
35
|
+
chain(:to) { |receiver| @to = receiver }
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# RSpec matcher to spec delegations.
|
2
|
+
|
3
|
+
RSpec::Matchers.define :delegate do |method|
|
4
|
+
match do |object|
|
5
|
+
@method = method
|
6
|
+
@via ||= method
|
7
|
+
@object = object
|
8
|
+
|
9
|
+
if !@object.respond_to?(@to)
|
10
|
+
raise "#{@object} does not respond to ##{@to}!"
|
11
|
+
end
|
12
|
+
|
13
|
+
@object.stub(@to).and_return double('receiver')
|
14
|
+
@object.send(@to).stub(@via).and_return :called
|
15
|
+
@object.send(@method) == :called
|
16
|
+
end
|
17
|
+
|
18
|
+
description do
|
19
|
+
"delegate ##{@method} to ##{@to}##{@via}"
|
20
|
+
end
|
21
|
+
|
22
|
+
failure_message_for_should do |text|
|
23
|
+
"expected #{@object} to delegate ##{@method} to ##{@to}##{@via}"
|
24
|
+
end
|
25
|
+
|
26
|
+
failure_message_for_should_not do |text|
|
27
|
+
"expected #{@object} not to delegate ##{@method} to ##{@to}##{@via}"
|
28
|
+
end
|
29
|
+
|
30
|
+
chain(:to) { |receiver| @to = receiver }
|
31
|
+
chain(:via) { |via| @via = via }
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ndlib-on-rspec/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = [
|
6
|
+
"Jeremy Friesen"
|
7
|
+
]
|
8
|
+
gem.email = [
|
9
|
+
"jeremy.n.friesen@gmail.com"
|
10
|
+
]
|
11
|
+
gem.description = %q{A handful of helpful Rspec matchers intended for reuse}
|
12
|
+
gem.summary = %q{A handful of helpful Rspec matchers intended for reuse}
|
13
|
+
gem.homepage = "http://github.com/ndlib/ndlib-on-rspec"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($\)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.name = "ndlib-on-rspec"
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.version = NdlibOnRspec::VERSION
|
21
|
+
|
22
|
+
gem.add_runtime_dependency(%q<rspec>, [">= 2.6.1"])
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::Matchers, "alias_from" do
|
4
|
+
subject { Comment.new }
|
5
|
+
|
6
|
+
describe '#alias_from' do
|
7
|
+
it 'handles :alias_method' do
|
8
|
+
subject.should alias_from(:parent).to(:ancestor)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'handles method definition' do
|
12
|
+
subject.should alias_from(:parent).to(:level_up)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'handles alias receiver with modification' do
|
16
|
+
lambda {
|
17
|
+
subject.should alias_from(:parent).to(:inspected_parent)
|
18
|
+
}.should(
|
19
|
+
raise_error(
|
20
|
+
RSpec::Expectations::ExpectationNotMetError,
|
21
|
+
/alias #parent to #inspected_parent/
|
22
|
+
)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'handles missing method' do
|
27
|
+
lambda {
|
28
|
+
subject.should alias_from(:parent).to(:obviously_missing)
|
29
|
+
}.should(
|
30
|
+
raise_error(
|
31
|
+
NameError,
|
32
|
+
/undefined method `obviously_missing'/
|
33
|
+
)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::Matchers, "delegate" do
|
4
|
+
subject { Comment.new }
|
5
|
+
|
6
|
+
describe '#delegate' do
|
7
|
+
it 'handles general delegate' do
|
8
|
+
subject.should delegate(:blog_name).to(:blog)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'handles general delegate with prefix' do
|
12
|
+
subject.should delegate(:blog_size).to(:blog).via(:size)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'handles missing method on delegated from object' do
|
16
|
+
lambda {
|
17
|
+
subject.should delegate(:obviously_missing).to(:blog)
|
18
|
+
}.should(
|
19
|
+
raise_error(
|
20
|
+
NameError,
|
21
|
+
/undefined method `obviously_missing'/
|
22
|
+
)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'handles missing method on delegated to object' do
|
27
|
+
lambda {
|
28
|
+
subject.should delegate(:parent).to(:blog)
|
29
|
+
}.should(
|
30
|
+
raise_error(
|
31
|
+
RSpec::Expectations::ExpectationNotMetError,
|
32
|
+
/delegate #parent to #blog#parent/
|
33
|
+
)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/ndlib-on-rspec")
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
6
|
+
# loaded once.
|
7
|
+
#
|
8
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
20
|
+
|
21
|
+
class Blog
|
22
|
+
def blog_name
|
23
|
+
'Hello World'
|
24
|
+
end
|
25
|
+
|
26
|
+
def size
|
27
|
+
'Wonderful'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
class Comment
|
31
|
+
def parent
|
32
|
+
@parent ||= Comment.new
|
33
|
+
end
|
34
|
+
alias_method :ancestor, :parent
|
35
|
+
|
36
|
+
def level_up
|
37
|
+
parent
|
38
|
+
end
|
39
|
+
|
40
|
+
def inspected_parent
|
41
|
+
parent.inspect
|
42
|
+
end
|
43
|
+
|
44
|
+
def blog
|
45
|
+
@blog ||= Blog.new
|
46
|
+
end
|
47
|
+
def blog_name
|
48
|
+
blog.blog_name
|
49
|
+
end
|
50
|
+
|
51
|
+
def blog_size
|
52
|
+
blog.size
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ndlib-on-rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeremy Friesen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.6.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.6.1
|
30
|
+
description: A handful of helpful Rspec matchers intended for reuse
|
31
|
+
email:
|
32
|
+
- jeremy.n.friesen@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rspec
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/ndlib-on-rspec.rb
|
44
|
+
- lib/ndlib-on-rspec/alias_from_matcher.rb
|
45
|
+
- lib/ndlib-on-rspec/delegate_matcher.rb
|
46
|
+
- lib/ndlib-on-rspec/version.rb
|
47
|
+
- ndlib-on-rspec.gemspec
|
48
|
+
- spec/ndlib-on-rspec/alias_from_matcher_spec.rb
|
49
|
+
- spec/ndlib-on-rspec/delegate_matcher_spec.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
homepage: http://github.com/ndlib/ndlib-on-rspec
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.24
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: A handful of helpful Rspec matchers intended for reuse
|
75
|
+
test_files:
|
76
|
+
- spec/ndlib-on-rspec/alias_from_matcher_spec.rb
|
77
|
+
- spec/ndlib-on-rspec/delegate_matcher_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
has_rdoc:
|