/
spec_helper.rb
52 lines (46 loc) · 1.62 KB
/
spec_helper.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
$LOAD_PATH.unshift(File.expand_path('../../../rspec-core/lib', __FILE__))
require 'rspec/core'
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'rspec/mocks'
$LOAD_PATH.unshift(File.expand_path('../../../rspec-expectations/lib', __FILE__))
require 'rspec/expectations'
module Macros
def treats_method_missing_as_private(options = {:noop => true, :subject => nil})
it "should have method_missing as private" do
with_ruby 1.8 do
self.class.describes.private_instance_methods.should include("method_missing")
end
with_ruby 1.9 do
self.class.describes.private_instance_methods.should include(:method_missing)
end
end
it "should not respond_to? method_missing (because it's private)" do
formatter = options[:subject] || described_class.new({ }, StringIO.new)
formatter.should_not respond_to(:method_missing)
end
if options[:noop]
it "should respond_to? all messages" do
formatter = described_class.new({ }, StringIO.new)
formatter.should respond_to(:just_about_anything)
end
it "should respond_to? anything, when given the private flag" do
formatter = described_class.new({ }, StringIO.new)
formatter.respond_to?(:method_missing, true).should be_true
end
end
end
end
module Rspec
module Matchers
def with_ruby(version)
yield if RUBY_VERSION =~ Regexp.compile("^#{version.to_s}")
end
end
end
Rspec::Core.configure do |config|
config.mock_with :rspec
config.color_enabled = true
config.extend(Macros)
config.include(Rspec::Matchers)
config.include(Rspec::Mocks::Methods)
end