summaryrefslogtreecommitdiff
path: root/spec/mspec/spec/guards/support_spec.rb
blob: f899ad02f64234a8356a67a6026d4ac4a563d0c9 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'spec_helper'
require 'mspec/guards'

describe Object, "#not_supported_on" do
  before :all do
    @verbose = $VERBOSE
    $VERBOSE = nil
    @ruby_engine = Object.const_get :RUBY_ENGINE if Object.const_defined? :RUBY_ENGINE
  end

  after :all do
    $VERBOSE = @verbose
    if @ruby_engine
      Object.const_set :RUBY_ENGINE, @ruby_engine
    else
      Object.send :remove_const, :RUBY_ENGINE
    end
  end

  before :each do
    ScratchPad.clear
  end

  it "raises an Exception when passed :ruby" do
    Object.const_set :RUBY_ENGINE, "jruby"
    lambda {
      not_supported_on(:ruby) { ScratchPad.record :yield }
    }.should raise_error(Exception)
    ScratchPad.recorded.should_not == :yield
  end

  it "does not yield when #implementation? returns true" do
    Object.const_set :RUBY_ENGINE, "jruby"
    not_supported_on(:jruby) { ScratchPad.record :yield }
    ScratchPad.recorded.should_not == :yield
  end

  it "yields when #standard? returns true" do
    Object.const_set :RUBY_ENGINE, "ruby"
    not_supported_on(:rubinius) { ScratchPad.record :yield }
    ScratchPad.recorded.should == :yield
  end

  it "yields when #implementation? returns false" do
    Object.const_set :RUBY_ENGINE, "jruby"
    not_supported_on(:rubinius) { ScratchPad.record :yield }
    ScratchPad.recorded.should == :yield
  end
end

describe Object, "#not_supported_on" do
  before :each do
    @guard = SupportedGuard.new
    SupportedGuard.stub(:new).and_return(@guard)
  end

  it "sets the name of the guard to :not_supported_on" do
    not_supported_on(:rubinius) { }
    @guard.name.should == :not_supported_on
  end

  it "calls #unregister even when an exception is raised in the guard block" do
    @guard.should_receive(:match?).and_return(false)
    @guard.should_receive(:unregister)
    lambda do
      not_supported_on(:rubinius) { raise Exception }
    end.should raise_error(Exception)
  end
end