spec/trema/host_spec.rb in trema-0.4.6 vs spec/trema/host_spec.rb in trema-0.4.7
- old
+ new
@@ -14,169 +14,169 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
-require File.join( File.dirname( __FILE__ ), "..", "spec_helper" )
-require "trema/host"
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require 'trema/host'
module Trema
describe Host do
- before {
+ before do
Host.instances.clear
- @cli = mock( "cli" )
- Cli.stub!( :new ).and_return( @cli )
- }
+ @cli = mock('cli')
+ Cli.stub!(:new).and_return(@cli)
+ end
describe :ip do
- context "when ip is omitted" do
+ context 'when ip is omitted' do
before { @stanza = {} }
- subject { Host.new( @stanza ).ip }
+ subject { Host.new(@stanza).ip }
- it { should == "192.168.0.1" }
+ it { should == '192.168.0.1' }
end
context "when ip \"192.168.100.100\"" do
- before { @stanza = { :ip => "192.168.100.100" } }
+ before { @stanza = { :ip => '192.168.100.100' } }
- subject { Host.new( @stanza ).ip }
+ subject { Host.new(@stanza).ip }
- it { should == "192.168.100.100" }
+ it { should == '192.168.100.100' }
end
end
describe :mac do
- context "when mac is omitted" do
+ context 'when mac is omitted' do
before { @stanza = {} }
- subject { Host.new( @stanza ).mac }
+ subject { Host.new(@stanza).mac }
- it { should == "00:00:00:00:00:01" }
+ it { should == '00:00:00:00:00:01' }
end
context "when mac \"00:00:00:aa:bb:cc\"" do
- before { @stanza = { :mac => "00:00:00:aa:bb:cc" } }
+ before { @stanza = { :mac => '00:00:00:aa:bb:cc' } }
- subject { Host.new( @stanza ).mac }
+ subject { Host.new(@stanza).mac }
- it { should == "00:00:00:aa:bb:cc" }
+ it { should == '00:00:00:aa:bb:cc' }
end
end
describe :netmask do
- context "when netmask is omitted" do
+ context 'when netmask is omitted' do
before { @stanza = {} }
- subject { Host.new( @stanza ).netmask }
+ subject { Host.new(@stanza).netmask }
- it { should == "255.255.255.255" }
+ it { should == '255.255.255.255' }
end
context "when netmask \"255.255.0.0\"" do
- before { @stanza = { :netmask => "255.255.0.0" } }
+ before { @stanza = { :netmask => '255.255.0.0' } }
- subject { Host.new( @stanza ).netmask }
+ subject { Host.new(@stanza).netmask }
- it { should == "255.255.0.0" }
+ it { should == '255.255.0.0' }
end
end
- context "when #add_arp_entries" do
+ context 'when #add_arp_entries' do
describe :cli do
- before {
- @host0 = Host.new( :name => "HOST 0" )
- @host1 = mock( "HOST 1" )
- @host2 = mock( "HOST 2" )
- @host3 = mock( "HOST 3" )
- }
+ before do
+ @host0 = Host.new(:name => 'HOST 0')
+ @host1 = mock('HOST 1')
+ @host2 = mock('HOST 2')
+ @host3 = mock('HOST 3')
+ end
- it "should add arp entries" do
- @cli.should_receive( :add_arp_entry ).with( @host1 )
- @cli.should_receive( :add_arp_entry ).with( @host2 )
- @cli.should_receive( :add_arp_entry ).with( @host3 )
+ it 'should add arp entries' do
+ @cli.should_receive(:add_arp_entry).with(@host1)
+ @cli.should_receive(:add_arp_entry).with(@host2)
+ @cli.should_receive(:add_arp_entry).with(@host3)
- @host0.add_arp_entry [ @host1, @host2, @host3 ]
+ @host0.add_arp_entry [@host1, @host2, @host3]
end
end
end
- context "when #run!" do
+ context 'when #run!' do
describe :cli do
- before {
- Phost.stub!( :new ).and_return( mock( "phost", :run! => nil ) )
- }
+ before do
+ Phost.stub!(:new).and_return(mock('phost', :run! => nil))
+ end
- it "should set IP and MAC address" do
- @cli.should_receive( :set_ip_and_mac_address )
+ it 'should set IP and MAC address' do
+ @cli.should_receive(:set_ip_and_mac_address)
- Host.new( :name => "Yutaro's host" ).run!
+ Host.new(:name => "Yutaro's host").run!
end
- context "when promisc on" do
- before { @cli.stub!( :set_ip_and_mac_address ) }
+ context 'when promisc on' do
+ before { @cli.stub!(:set_ip_and_mac_address) }
- it "should enable promisc" do
- @cli.should_receive( :enable_promisc )
+ it 'should enable promisc' do
+ @cli.should_receive(:enable_promisc)
- Host.new( :name => "Yutaro's host", :promisc => true ).run!
+ Host.new(:name => "Yutaro's host", :promisc => true).run!
end
end
end
end
- context "when #send_packets" do
+ context 'when #send_packets' do
describe :cli do
- before {
- @dest = mock( "dest" )
- @options = mock( "options" )
- }
+ before do
+ @dest = mock('dest')
+ @options = mock('options')
+ end
- it "should send_packets" do
- @cli.should_receive( :send_packets ).with( @dest, @options )
+ it 'should send_packets' do
+ @cli.should_receive(:send_packets).with(@dest, @options)
- Host.new( :name => "Yutaro's host" ).send_packet @dest, @options
+ Host.new(:name => "Yutaro's host").send_packet @dest, @options
end
end
end
- context "when getting stats" do
- before {
- @stats = mock( "stats" )
- @host = Host.new( :name => "Yutaro's host" )
- }
+ context 'when getting stats' do
+ before do
+ @stats = mock('stats')
+ @host = Host.new(:name => "Yutaro's host")
+ end
- context "when #tx_stats" do
+ context 'when #tx_stats' do
describe :cli do
- it "should get tx stats" do
- @cli.should_receive( :tx_stats ).and_return( @stats )
+ it 'should get tx stats' do
+ @cli.should_receive(:tx_stats).and_return(@stats)
- expect( @host.tx_stats ).to eq( @stats )
+ expect(@host.tx_stats).to eq(@stats)
end
end
end
- context "when #rx_stats" do
+ context 'when #rx_stats' do
describe :cli do
- it "should get rx stats" do
- @cli.should_receive( :rx_stats ).and_return( @stats )
+ it 'should get rx stats' do
+ @cli.should_receive(:rx_stats).and_return(@stats)
- expect( @host.rx_stats ).to eq( @stats )
+ expect(@host.rx_stats).to eq(@stats)
end
end
end
end
end