forked from bleything/midiator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinterface_spec.rb
140 lines (107 loc) · 3.58 KB
/
interface_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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env ruby
#
# Contains the specifications for the MIDIator::Interface class.
#
# == Authors
#
# * Ben Bleything <[email protected]>
#
# == Contributors
#
# * Giles Bowkett
#
# == Copyright
#
# Copyright (c) 2008 Ben Bleything
#
# This code released under the terms of the MIT license.
#
require File.join( File.dirname(__FILE__), 'lib', 'spec_helper.rb' )
describe MIDIator::Interface do
before( :each ) do
@driver_name = 'i_like_bees'
@interface = MIDIator::Interface.new
@driver_class = mock( "driver class" )
end
describe "auto-detects the correct driver for your platform" do
before( :all ) do
# remember platform so we can reset it later
@ruby_platform = Platform::IMPL
# suppress warnings (http://www.ruby-forum.com/topic/127608)
$-v = nil
end
after( :all ) do
# reset platform to whatever is correct for our platform
Platform::IMPL = @ruby_platform
# restore warnings (http://www.ruby-forum.com/topic/127608)
$-v = false
end
it "selects WinMM for Windows" do
Platform::IMPL = :mswin
@interface.should_receive( :use ).with( :winmm )
@interface.autodetect_driver
end
it "selects CoreMIDI for OSX" do
Platform::IMPL = :macosx
@interface.should_receive( :use ).with( :core_midi )
@interface.autodetect_driver
end
it "selects ALSA for Linux" do
Platform::IMPL = :linux
@interface.should_receive( :use ).with( :alsa )
@interface.autodetect_driver
end
end
describe "provides the #use method to load/specify a MIDI driver" do
it "requires the driver's file from midiator/drivers" do
path = "midiator/drivers/#{@driver_name}"
@interface.should_receive( :require ).with( path )
# stub out the rest of #use
Object.should_receive( :module_eval ).and_return(
mock( 'foo', :null_object => true )
)
@interface.use( @driver_name )
end
it "captures a LoadError and gives the user a slightly better message" do
@interface.should_receive( :require ).and_raise( LoadError )
lambda {
@interface.use( @driver_name )
}.should raise_error( LoadError, "Could not load driver '#{@driver_name.to_s}'.")
end
it "instantiates the driver's class" do
@interface.stub!( :require )
Object.should_receive( :module_eval ).with(
"::MIDIator::Driver::ILikeBees"
).and_return( Class.new )
@interface.use( @driver_name )
end
it "correctly spells MIDI if the driver name includes it" do
@interface.stub!( :require )
Object.should_receive( :module_eval ).with(
"::MIDIator::Driver::SomeClassThatHasMIDIInItsName"
).and_return( Class.new )
@interface.use( "some_class_that_has_midi_in_its_name" )
end
it "correctly spells ALSA when the ALSA driver is requested" do
@interface.stub!( :require )
Object.should_receive( :module_eval ).with(
"::MIDIator::Driver::ALSA"
).and_return( Class.new )
@interface.use( :alsa )
end
it "correctly spells WinMM when the WinMM driver is requested" do
@interface.stub!( :require )
Object.should_receive( :module_eval ).with(
"::MIDIator::Driver::WinMM"
).and_return( Class.new )
@interface.use( :winmm )
end
it "correctly spells DLSSynth when the DLSSynth driver is requested" do
@interface.stub!( :require )
Object.should_receive( :module_eval ).with(
"::MIDIator::Driver::DLSSynth"
).and_return( Class.new )
@interface.use( :dls_synth )
end
end
end