ndlib-on-rspec 0.0.1 → 0.0.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.
data/README.md
CHANGED
@@ -18,7 +18,15 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
Take a look at the /spec directory
|
21
|
+
Take a look at the /spec directory for greater clarity
|
22
|
+
|
23
|
+
### :alias_from
|
24
|
+
|
25
|
+
object.should alias_from(:one_method).to(:another)
|
26
|
+
|
27
|
+
### :delegate
|
28
|
+
|
29
|
+
object.should delegate(:blog_name).to(:blog).via(:name)
|
22
30
|
|
23
31
|
## Contributing
|
24
32
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
RSpec::Matchers.define :have_method do |method_name|
|
2
|
+
match do |object|
|
3
|
+
@method_name = method_name
|
4
|
+
@arity ||= '0'.to_i
|
5
|
+
if %r{^(?<prefix>\.|\#)(?<normalized_method_name>.*)} =~ method_name.to_s
|
6
|
+
@normalized_method_name = normalized_method_name
|
7
|
+
@klass = object.is_a?(Class) ? object : object.class
|
8
|
+
if prefix == '.'
|
9
|
+
@klass.method(@normalized_method_name).arity == @arity
|
10
|
+
elsif prefix == '#'
|
11
|
+
@klass.instance_method(@normalized_method_name).arity == @arity
|
12
|
+
end
|
13
|
+
else
|
14
|
+
@method_name = "##{method_name}"
|
15
|
+
@klass = object.class
|
16
|
+
@normalized_method_name = method_name
|
17
|
+
@object = object
|
18
|
+
@object.method(@normalized_method_name).arity == @arity
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
description do
|
23
|
+
"have_method #{@method_name} [arity:#{@arity}]"
|
24
|
+
end
|
25
|
+
|
26
|
+
failure_message_for_should do |text|
|
27
|
+
"expected #{@klass} to have_method #{@method_name} [arity:#{@arity}]"
|
28
|
+
end
|
29
|
+
|
30
|
+
failure_message_for_should_not do |text|
|
31
|
+
"expected #{@klass} not to delegate #{@method_name} [arity:#{@arity}]"
|
32
|
+
end
|
33
|
+
|
34
|
+
chain(:with_arity) { |arity| @arity = arity }
|
35
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::Matchers, "have_method" do
|
4
|
+
subject { Comment.new }
|
5
|
+
|
6
|
+
describe '#have_method' do
|
7
|
+
context 'without arity' do
|
8
|
+
|
9
|
+
it 'handles have_method with instance method lookup' do
|
10
|
+
subject.should have_method('#blog_name')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'handles have_method with instance method lookup' do
|
14
|
+
subject.should have_method(:blog_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'handles have_method with class method' do
|
18
|
+
subject.should have_method('.a_class_method_name')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'handles have_method with assumed instance method for class' do
|
22
|
+
subject.class.should have_method(:a_class_method_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'handles have_method with explicit instance method for class' do
|
26
|
+
subject.class.should have_method(".a_class_method_name")
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with arity' do
|
32
|
+
subject do
|
33
|
+
Class.new do
|
34
|
+
def method_with_one_param(one)
|
35
|
+
end
|
36
|
+
def method_with_splat_arg(*args)
|
37
|
+
end
|
38
|
+
end.new
|
39
|
+
end
|
40
|
+
it 'handles arity with explicit arg' do
|
41
|
+
subject.should have_method("#method_with_one_param").with_arity(1)
|
42
|
+
end
|
43
|
+
it 'handles defined method with wrong arity' do
|
44
|
+
lambda {
|
45
|
+
subject.should have_method("#method_with_one_param").with_arity(2)
|
46
|
+
}.should(
|
47
|
+
raise_error(
|
48
|
+
RSpec::Expectations::ExpectationNotMetError,
|
49
|
+
%r{have_method \#method_with_one_param \[arity\:2\]}
|
50
|
+
))
|
51
|
+
end
|
52
|
+
it 'handles arity with splat args' do
|
53
|
+
subject.should have_method("#method_with_splat_arg").with_arity(-1)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ndlib-on-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -43,10 +43,12 @@ files:
|
|
43
43
|
- lib/ndlib-on-rspec.rb
|
44
44
|
- lib/ndlib-on-rspec/alias_from_matcher.rb
|
45
45
|
- lib/ndlib-on-rspec/delegate_matcher.rb
|
46
|
+
- lib/ndlib-on-rspec/have_method_matcher.rb
|
46
47
|
- lib/ndlib-on-rspec/version.rb
|
47
48
|
- ndlib-on-rspec.gemspec
|
48
49
|
- spec/ndlib-on-rspec/alias_from_matcher_spec.rb
|
49
50
|
- spec/ndlib-on-rspec/delegate_matcher_spec.rb
|
51
|
+
- spec/ndlib-on-rspec/have_method_matcher_spec.rb
|
50
52
|
- spec/spec_helper.rb
|
51
53
|
homepage: http://github.com/ndlib/ndlib-on-rspec
|
52
54
|
licenses: []
|
@@ -75,5 +77,5 @@ summary: A handful of helpful Rspec matchers intended for reuse
|
|
75
77
|
test_files:
|
76
78
|
- spec/ndlib-on-rspec/alias_from_matcher_spec.rb
|
77
79
|
- spec/ndlib-on-rspec/delegate_matcher_spec.rb
|
80
|
+
- spec/ndlib-on-rspec/have_method_matcher_spec.rb
|
78
81
|
- spec/spec_helper.rb
|
79
|
-
has_rdoc:
|