/
differentiate_block_method_types_spec.rb
39 lines (33 loc) · 1.2 KB
/
differentiate_block_method_types_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'spec_helper'
module RSpec
module Matchers
describe DifferentiateBlockMethodTypes do
let(:differentiator) do
DifferentiateBlockMethodTypes.new do
def some_instance_method_1; end
def self.some_singleton_method_1; end
define_method(:some_instance_method_2) { }
if RUBY_VERSION.to_f > 1.8
define_singleton_method(:some_singleton_method_2) { }
else
def self.some_singleton_method_2; end
end
end
end
it 'differentiates singleton method defs from instance method defs' do
expect(differentiator.instance_methods).to eq([:some_instance_method_1, :some_instance_method_2])
expect(differentiator.singleton_methods).to eq([:some_singleton_method_1, :some_singleton_method_2])
end
it 'passes the given args through to the block' do
expect { |b|
DifferentiateBlockMethodTypes.new(1, 2, &b)
}.to yield_with_args(1, 2)
end
it 'ignores unrecognized DSL methods called in the block' do
expect {
DifferentiateBlockMethodTypes.new { foo.bar; some_dsl { nested } }
}.not_to raise_error
end
end
end
end