Skip to content

Commit

Permalink
Don't collide Term::ANSIColor and Yast::Term
Browse files Browse the repository at this point in the history
Fixes Coveralls reporting, avoiding:

Formatter Coveralls::SimpleCov::Formatter failed with TypeError:
  Term is not a module
  (/usr/lib64/ruby/gems/2.2.0/gems/term-ansicolor-1.3.0/lib/term/ansicolor.rb:1:in `<top (required)>')
  • Loading branch information
mvidner committed Jul 1, 2015
1 parent fc0add3 commit 414a6e2
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 123 deletions.
4 changes: 2 additions & 2 deletions test/dns_test.rb
@@ -1,12 +1,12 @@
#!/usr/bin/env rspec

ENV["Y2DIR"] = File.expand_path("../../src", __FILE__)
require_relative "test_helper"

require "yast"
require_relative "SCRStub"

module Yast
RSpec.configure do |c|
::RSpec.configure do |c|
c.include SCRStub
end

Expand Down
62 changes: 30 additions & 32 deletions test/ifroute_test.rb
Expand Up @@ -4,12 +4,10 @@

require "yast"

include Yast

Yast.import "NetworkInterfaces"
Yast.import "Routing"

describe "Routing#Read" do
describe "Yast::Routing#Read" do
ROUTES_FILE = [
{
"destination" => "default",
Expand All @@ -28,58 +26,58 @@
]

before(:each) do
allow(NetworkInterfaces)
allow(Yast::NetworkInterfaces)
.to receive(:Read)
.and_return(true)
allow(NetworkInterfaces)
allow(Yast::NetworkInterfaces)
.to receive(:List)
.and_return(["eth0"])
allow(SCR)
allow(Yast::SCR)
.to receive(:Read)
.and_return(nil)
end

it "loades ifroute-* files" do
allow(SCR)
allow(Yast::SCR)
.to receive(:Read)
.with(path(".routes"))
.and_return([])

expect(SCR)
expect(Yast::SCR)
.to receive(:Read)
.with(path(".ifroute-eth0"))
.and_return(IFROUTE_FILE)
expect(Routing.Read).to be true
expect(Routing.Routes).not_to be_empty
expect(Yast::Routing.Read).to be true
expect(Yast::Routing.Routes).not_to be_empty
end

it "replace implicit device name using explicit one" do
expect(SCR)
expect(Yast::SCR)
.to receive(:Read)
.with(path(".ifroute-eth0"))
.and_return(IFROUTE_FILE)
expect(Routing.Read).to be true
expect(Yast::Routing.Read).to be true
# check if implicit device name "-" is rewritten according device name
# which ifroute belongs to
expect(Routing.Routes.first["device"])
expect(Yast::Routing.Routes.first["device"])
.to eql "eth0"
end

it "removes duplicit routes" do
expect(SCR)
expect(Yast::SCR)
.to receive(:Read)
.with(path(".routes"))
.and_return(ROUTES_FILE)
expect(SCR)
expect(Yast::SCR)
.to receive(:Read)
.with(path(".ifroute-eth0"))
.and_return(IFROUTE_FILE)
expect(Routing.Read).to be true
expect(Routing.Routes.size).to eql 1
expect(Yast::Routing.Read).to be true
expect(Yast::Routing.Routes.size).to eql 1
end
end

describe "Routing#write_routes" do
describe "Yast::Routing#write_routes" do
ROUTES_WITH_DEV = [
{
"destination" => "default",
Expand All @@ -96,39 +94,39 @@
]

it "writes device assigned routes into correct ifroute file" do
allow(SCR)
allow(Yast::SCR)
.to receive(:Read)
.with(path(".target.size"), RoutingClass::ROUTES_FILE)
.with(path(".target.size"), Yast::RoutingClass::ROUTES_FILE)
.and_return(1)
allow(Routing)
allow(Yast::Routing)
.to receive(:devices)
.and_return(["eth0", "eth1", "eth2"])
expect(SCR)
expect(Yast::SCR)
.to receive(:Execute)
.with(path(".target.bash"), /^\/bin\/cp/)
.and_return(0)

expect(SCR)
expect(Yast::SCR)
.to receive(:Write)
.with(path(".ifroute-eth0"), anything)
.and_return(true)
expect(SCR)
expect(Yast::SCR)
.to receive(:Write)
.with(path(".ifroute-eth1"), anything)
.and_return(true)
expect(SCR)
expect(Yast::SCR)
.to receive(:Execute)
.with(path(".target.remove"), "/etc/sysconfig/network/ifroute-eth2")
.and_return(true)
expect(SCR)
expect(Yast::SCR)
.to receive(:Write)
.with(path(".target.string"), "/etc/sysconfig/network/routes", "")
.and_return(true)
expect(Routing.write_routes(ROUTES_WITH_DEV)).to be true
expect(Yast::Routing.write_routes(ROUTES_WITH_DEV)).to be true
end
end

describe "Routing#Write" do
describe "Yast::Routing#Write" do
AY_ROUTES = [
# empty AY config
{},
Expand Down Expand Up @@ -161,20 +159,20 @@
it "does write route configuration files, ##{i}" do
# Devices which have already been imported by Lan.Import have to be read.
# (bnc#900352)
allow(NetworkInterfaces)
allow(Yast::NetworkInterfaces)
.to receive(:List)
.with("")
.and_return(["eth0"])

Routing.Import(ay_test)
Yast::Routing.Import(ay_test)

expect(Routing)
expect(Yast::Routing)
.to receive(:write_route_file)
.twice
.with(kind_of(String), ay_test.fetch("routes", []))
.and_return true

Routing.Write
Yast::Routing.Write
end
end
end
7 changes: 3 additions & 4 deletions test/install_inf_convertor_test.rb
Expand Up @@ -4,7 +4,6 @@

require "yast"
require "network/install_inf_convertor"
include Yast # for path shortcut and avoid namespace

Yast.import "Proxy"

Expand Down Expand Up @@ -67,7 +66,7 @@

it "returns empty string even in autoinst mode" do
Yast.import "Mode"
allow(Mode).to receive(:autoinst) { true }
allow(Yast::Mode).to receive(:autoinst) { true }

expect(@install_inf_convertor.send(:dev_name)).to be_empty
end
Expand Down Expand Up @@ -113,7 +112,7 @@

describe "#write_ifcfg" do
it "creates ifcfg file for #{@device}" do
expect(SCR)
expect(Yast::SCR)
.to receive(:Write)
.with(path(".target.string"), /.*-#{@device}/, "") { true }
expect(@install_inf_convertor.send(:write_ifcfg, "")).to eql true
Expand Down Expand Up @@ -165,7 +164,7 @@
it "creates a valid ifcfg for netconfig" do
expect(ifcfg = @install_inf_convertor.send(:create_ifcfg)).not_to be_empty
expect(ifcfg).to include "BOOTPROTO='static'"
expect(ifcfg).to include "IPADDR='#{@ip}\/#{Netmask.ToBits(@netmask)}'"
expect(ifcfg).to include "IPADDR='#{@ip}\/#{Yast::Netmask.ToBits(@netmask)}'"
end
end

Expand Down
2 changes: 0 additions & 2 deletions test/lan_udev_auto_test.rb
Expand Up @@ -73,8 +73,6 @@
end

describe "LanUdevAuto#Write" do
include Yast

ATTR = "ATTR{address}"
VALUE = "aa:BB:cc:DD:ee:FF"
NAME = "custom-name"
Expand Down
1 change: 0 additions & 1 deletion test/link_handlers_test.rb
Expand Up @@ -12,7 +12,6 @@ def initialize
end

describe "phy_connected?" do
include Yast
subject { LinkHandlersClass.new }

before(:each) do
Expand Down
22 changes: 11 additions & 11 deletions test/netcard_test.rb
Expand Up @@ -69,9 +69,8 @@

require "yast"

include Yast
include UIShortcuts
include I18n
include Yast::UIShortcuts
include Yast::I18n

Yast.import "LanItems"

Expand All @@ -82,7 +81,7 @@

# mocking only neccessary parts of Yast::LanItems so we need not to call
# and mock inputs for Yast::LanItems.Read here
@lan_items.Items = deep_copy(MOCKED_ITEMS)
@lan_items.Items = Yast::deep_copy(MOCKED_ITEMS)
end

it "returns empty list when querying device name with nil or empty input" do
Expand Down Expand Up @@ -139,7 +138,7 @@
before(:each) do
@lan_items = Yast::LanItems
@lan_items.main
@lan_items.Items = deep_copy(MOCKED_ITEMS)
@lan_items.Items = Yast::deep_copy(MOCKED_ITEMS)
end

it "returns description and uses custom name if present" do
Expand Down Expand Up @@ -183,7 +182,7 @@
before(:each) do
@lan_items = Yast::LanItems
@lan_items.main
@lan_items.Items = deep_copy(MOCKED_ITEMS)
@lan_items.Items = Yast::deep_copy(MOCKED_ITEMS)
end

it "removes an existing item" do
Expand Down Expand Up @@ -218,7 +217,7 @@
before(:each) do
@lan_items = Yast::LanItems
@lan_items.main
@lan_items.Items = deep_copy(MOCKED_ITEMS)
@lan_items.Items = Yast::deep_copy(MOCKED_ITEMS)
end

it "returns name provided by hwinfo if not configured" do
Expand All @@ -235,24 +234,25 @@
end

describe "LanItemsClass#SetItemName" do
subject { Yast::LanItems }
let(:new_name) { "new_name" }

# this test covers bnc#914833
it "doesn't try to update udev rules when none exists for the item" do
allow(LanItems)
allow(subject)
.to receive(:Items)
.and_return(MOCKED_ITEMS)

item_id = LanItems.Items.find { |_k, v| !v.key?("udev") }.first
expect(LanItems.SetItemName(item_id, new_name)).to eql new_name
item_id = subject.Items.find { |_k, v| !v.key?("udev") }.first
expect(subject.SetItemName(item_id, new_name)).to eql new_name
end
end

describe "LanItemsClass#FindAndSelect" do
before(:each) do
@lan_items = Yast::LanItems
@lan_items.main
@lan_items.Items = deep_copy(MOCKED_ITEMS)
@lan_items.Items = Yast::deep_copy(MOCKED_ITEMS)
end

it "finds configured device" do
Expand Down
1 change: 1 addition & 0 deletions test/network_autoyast_test.rb
Expand Up @@ -139,6 +139,7 @@
let(:network_autoyast) { Yast::NetworkAutoYast.instance }

it "merges all necessary stuff" do
Yast::UI.as_null_object
expect(network_autoyast).to receive(:merge_dns)
expect(network_autoyast).to receive(:merge_routing)
expect(network_autoyast).to receive(:merge_devices)
Expand Down
14 changes: 9 additions & 5 deletions test/read_hardware_test.rb
@@ -1,16 +1,20 @@
#! /usr/bin/env rspec

ENV["Y2DIR"] = File.expand_path("../../src", __FILE__)
require_relative "test_helper"

require "yast"

include Yast

require_relative "netcard_probe_helper"

Yast.include self, "network/routines.rb"
class ReadHardwareTestClass
def initialize
Yast.include self, "network/routines.rb"
end
end

describe "#ReadHardware" do
subject { ReadHardwareTestClass.new }

def storage_only_devices
devices = probe_netcard.select { |n| n["storageonly"] }
devices.map { |d| d["dev_name"] }
Expand All @@ -21,7 +25,7 @@ def storage_only_devices
allow(Yast::SCR).to receive(:Read).and_return(nil)
allow(Yast::SCR).to receive(:Read).with(path(".probe.netcard")) { probe_netcard }

read_storage_devices = ReadHardware("netcard").select do |d|
read_storage_devices = subject.ReadHardware("netcard").select do |d|
storage_only_devices.include? d["dev_name"]
end

Expand Down
4 changes: 2 additions & 2 deletions test/remote_test.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env rspec

ENV["Y2DIR"] = File.expand_path("../../src", __FILE__)
require_relative "test_helper"

require "yast"
require_relative "SCRStub"
Expand All @@ -11,7 +11,7 @@ module Yast
import "Package"
import "Packages"

RSpec.configure do |c|
::RSpec.configure do |c|
c.include SCRStub
end

Expand Down

0 comments on commit 414a6e2

Please sign in to comment.