Skip to content

Commit

Permalink
add test for proposal client
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Nov 20, 2014
1 parent b03232e commit 4810296
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 14 deletions.
2 changes: 1 addition & 1 deletion library/general/src/lib/installation/proposal_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Installation
# ::Installation::ExampleProposal.run
# @see for example client in installation clone_proposal.rb
# @see proposal_api_reference to get overview of proposal client API
class ProposalClient < Client
class ProposalClient < Yast::Client
include Yast::Logger

# Entry point for calling client. Only part needed in client rb file.
Expand Down
1 change: 1 addition & 0 deletions library/general/test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ TESTS = \
linuxrc_test.rb \
os_release_test.rb \
popup_test.rb \
proposal_client_test.rb \
agents_test/proc_meminfo_agent_test.rb

TEST_EXTENSIONS = .rb
Expand Down
3 changes: 1 addition & 2 deletions library/general/test/asciifile_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#! /usr/bin/env rspec

require File.expand_path("../test_helper.rb", __FILE__)
require_relative "test_helper"

require "yast"
include Yast

Yast.import "AsciiFile"
Expand Down
4 changes: 1 addition & 3 deletions library/general/test/hooks_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#! /usr/bin/env rspec

require File.expand_path("../test_helper.rb", __FILE__)

require "yast"
require_relative "test_helper"

module Yast
import 'Hooks'
Expand Down
3 changes: 1 addition & 2 deletions library/general/test/linuxrc_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env rspec

require File.expand_path("../test_helper.rb", __FILE__)
require_relative "test_helper"

require "yast"
include Yast

Yast.import "Linuxrc"
Expand Down
4 changes: 1 addition & 3 deletions library/general/test/os_release_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#! /usr/bin/env rspec

require File.expand_path("../test_helper.rb", __FILE__)

require "yast"
require_relative "test_helper"

Yast.import "OSRelease"
Yast.import "FileUtils"
Expand Down
3 changes: 1 addition & 2 deletions library/general/test/popup_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#! /usr/bin/env rspec

require File.expand_path("../test_helper.rb", __FILE__)
require_relative "test_helper"

require "yast"
include Yast

Yast.import "Popup"
Expand Down
108 changes: 108 additions & 0 deletions library/general/test/proposal_client_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
require_relative "test_helper"

require "installation/proposal_client"

class TestProposal < ::Installation::ProposalClient
def make_proposal(args)
args.empty? ? "make_proposal" : args
end

def ask_user(args)
args.empty? ? "ask_user" : args
end

def description
"description"
end

def write(args)
args.empty? ? "write" : args
end
end

describe ::Installation::ProposalClient do
subject { ::TestProposal }
describe ".run" do
it "raise exception if unknown first argument is passed" do
allow(Yast::WFM).to receive(:Args).and_return(["Unknown", {}])
expect{::Installation::ProposalClient.run}.to raise_error
end

context "first client argument is MakeProposal" do
before do
allow(Yast::WFM).to receive(:Args).and_return(["MakeProposal", {}])
end

it "dispatch call to abstract method make_proposal" do
expect(subject.run).to eq "make_proposal"
end

it "passes argument hash to abstract method" do
test_params = { :a => :b, :c => :d }
allow(Yast::WFM).to receive(:Args).and_return(["MakeProposal", test_params])

expect(subject.run).to eq test_params
end

it "raise NotImplementedError exception if abstract method not defined" do
expect{::Installation::ProposalClient.run}.to raise_error(NotImplementedError)
end
end

context "first client argument is AskUser" do
before do
allow(Yast::WFM).to receive(:Args).and_return(["AskUser", {}])
end

it "dispatch call to abstract method ask_user" do
expect(subject.run).to eq "ask_user"
end

it "passes argument hash to abstract method" do
test_params = { :a => :b, :c => :d }
allow(Yast::WFM).to receive(:Args).and_return(["AskUser", test_params])

expect(subject.run).to eq test_params
end

it "raise NotImplementedError exception if abstract method not defined" do
expect{::Installation::ProposalClient.run}.to raise_error(NotImplementedError)
end
end

context "first client argument is Description" do
before do
allow(Yast::WFM).to receive(:Args).and_return(["Description", {}])
end

it "dispatch call to abstract method description" do
expect(subject.run).to eq "description"
end

it "raise NotImplementedError exception if abstract method not defined" do
expect{::Installation::ProposalClient.run}.to raise_error(NotImplementedError)
end
end

context "first client argument is Write" do
before do
allow(Yast::WFM).to receive(:Args).and_return(["Write", {}])
end

it "dispatch call to abstract method write" do
expect(subject.run).to eq "write"
end

it "passes argument hash to abstract method" do
test_params = { :a => :b, :c => :d }
allow(Yast::WFM).to receive(:Args).and_return(["Write", test_params])

expect(subject.run).to eq test_params
end

it "just log error if abstract method not defined" do
expect{::Installation::ProposalClient.run}.to_not raise_error
end
end
end
end
3 changes: 2 additions & 1 deletion library/general/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

top_srcdir = File.expand_path("../../../..", __FILE__)
inc_dirs = Dir.glob("#{top_srcdir}/library/*/src")
ENV["Y2DIR"] = inc_dirs.join(":")

require "yast"

def set_root_path(directory)
check_version = false
handle = Yast::WFM.SCROpen("chroot=#{directory}:scr", check_version)
Expand Down

0 comments on commit 4810296

Please sign in to comment.