blob: 943b558ed3fc40914a1a4229530379369d0f311d (
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
|
require 'spec_helper'
require 'mspec/guards'
RSpec.describe Object, "#big_endian" do
before :each do
@guard = BigEndianGuard.new
allow(BigEndianGuard).to receive(:new).and_return(@guard)
ScratchPad.clear
end
it "yields on big-endian platforms" do
allow(@guard).to receive(:pattern).and_return([?\001])
big_endian { ScratchPad.record :yield }
expect(ScratchPad.recorded).to eq(:yield)
end
it "does not yield on little-endian platforms" do
allow(@guard).to receive(:pattern).and_return([?\000])
big_endian { ScratchPad.record :yield }
expect(ScratchPad.recorded).not_to eq(:yield)
end
it "sets the name of the guard to :big_endian" do
big_endian { }
expect(@guard.name).to eq(:big_endian)
end
it "calls #unregister even when an exception is raised in the guard block" do
allow(@guard).to receive(:pattern).and_return([?\001])
expect(@guard).to receive(:unregister)
expect do
big_endian { raise Exception }
end.to raise_error(Exception)
end
end
RSpec.describe Object, "#little_endian" do
before :each do
@guard = BigEndianGuard.new
allow(BigEndianGuard).to receive(:new).and_return(@guard)
ScratchPad.clear
end
it "yields on little-endian platforms" do
allow(@guard).to receive(:pattern).and_return([?\000])
little_endian { ScratchPad.record :yield }
expect(ScratchPad.recorded).to eq(:yield)
end
it "does not yield on big-endian platforms" do
allow(@guard).to receive(:pattern).and_return([?\001])
little_endian { ScratchPad.record :yield }
expect(ScratchPad.recorded).not_to eq(:yield)
end
end
|