Skip to content

Commit

Permalink
Merge pull request #25 from nathan/fix_warnings
Browse files Browse the repository at this point in the history
Fixing defined constant error in usb_serial_spec
  • Loading branch information
austinbv committed Feb 22, 2013
2 parents 3c9766d + faa868c commit 7fe0ab1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions spec/lib/tx_rx/usb_serial_spec.rb
Expand Up @@ -14,15 +14,15 @@ module Dino
context "on windows" do
it 'should instantiate a new SerialPort for each usb tty device found' do
original_platform = RUBY_PLATFORM
RUBY_PLATFORM = "mswin"
Constants.redefine(:RUBY_PLATFORM, "mswin", :on => Object)
subject.should_receive(:tty_devices).and_return(["COM1", "COM2", "COM3", "COM4"])
SerialPort.should_receive(:new).with('COM1', TxRx::USBSerial::BAUD).and_return(mock_serial = mock)
SerialPort.should_receive(:new).with('COM2', TxRx::USBSerial::BAUD).and_return(mock)
SerialPort.should_receive(:new).with('COM3', TxRx::USBSerial::BAUD).and_return(mock)
SerialPort.should_receive(:new).with('COM4', TxRx::USBSerial::BAUD).and_return(mock)

subject.io.should == mock_serial
RUBY_PLATFORM = original_platform
Constants.redefine(:RUBY_PLATFORM, original_platform, :on => Object)
end
end

Expand Down
11 changes: 10 additions & 1 deletion spec/spec_helper.rb
@@ -1,3 +1,12 @@
require 'rspec'

require File.expand_path(File.join('../..', 'lib/dino'), __FILE__)
require File.expand_path(File.join('../..', 'lib/dino'), __FILE__)

# Nice little helper module to redefine constants quietly.
module Constants
def self.redefine(const, value, opts={})
opts = {:on => self.class}.merge(opts)
opts[:on].send(:remove_const, const) if self.class.const_defined?(const)
opts[:on].const_set(const, value)
end
end

0 comments on commit 7fe0ab1

Please sign in to comment.