Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed May 10, 2017
1 parent b7c2533 commit c7c4b9a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/cosmos/script/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def clear(display_name)
end
end

def clear_all(target = '')
def clear_all(target = nil)
run_tlm_viewer("clear_all") do |tlm_viewer|
tlm_viewer.clear_all(target)
end
Expand Down
10 changes: 5 additions & 5 deletions lib/cosmos/tools/tlm_viewer/tlm_viewer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def clear(display_name)
TlmViewer.instance.clear(display_name)
end

def clear_all(target)
def clear_all(target = nil)
TlmViewer.instance.clear_all(target)
end
end
Expand Down Expand Up @@ -485,15 +485,15 @@ def clear(screen_full_name)
end

# Close all screens
def clear_all(target_name)
if target_name.empty?
Qt.execute_in_main_thread(true) { Screen.close_all_screens(self) }
else
def clear_all(target_name = nil)
if target_name
screens = @tlm_viewer_config.screen_infos.values.select do |screen_info|
screen_info.target_name == target_name.upcase
end
raise "Unknown screen target: #{target_name.upcase}" if screens.length == 0
screens.each { |screen_info| close_screen(screen_info) }
else
Qt.execute_in_main_thread(true) { Screen.close_all_screens(self) }
end
end

Expand Down
19 changes: 17 additions & 2 deletions spec/script/tools_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module Cosmos
allow_any_instance_of(Object).to receive(:sleep)
allow_any_instance_of(Object).to receive(:cosmos_script_sleep).and_return(true)
allow(Cosmos).to receive(:run_process)
expect { display("HI") }.to raise_error(RuntimeError, /HI could not be displayed/)
expect { display("HI") }.to raise_error(RuntimeError, /Could not display HI/)
end

it "complains if the screen doesn't exist" do
Expand All @@ -83,7 +83,7 @@ module Cosmos
allow_any_instance_of(Object).to receive(:sleep)
allow_any_instance_of(Object).to receive(:cosmos_script_sleep).and_return(true)
allow(Cosmos).to receive(:run_process)
expect { clear("HI") }.to raise_error(RuntimeError, /HI could not be cleared/)
expect { clear("HI") }.to raise_error(RuntimeError, /Could not clear HI/)
end

it "complains if the screen doesn't exist" do
Expand All @@ -92,6 +92,21 @@ module Cosmos
end
end

describe "clear_all" do
it "closes all telemetry viewer screens" do
allow_any_instance_of(JsonDRbObject).to receive(:clear_all)
clear_all
end

it "complains if unable to start telemetry viewer" do
# Avoid the needless delay by stubbing sleep
allow_any_instance_of(Object).to receive(:sleep)
allow_any_instance_of(Object).to receive(:cosmos_script_sleep).and_return(true)
allow(Cosmos).to receive(:run_process)
expect { clear_all }.to raise_error(RuntimeError, /Could not clear_all/)
end
end

describe "ScriptRunnerFrame methods" do
it "calls various ScriptRunnerFrame methods" do
class Dummy; def method_missing(meth, *args, &block); end; end
Expand Down

0 comments on commit c7c4b9a

Please sign in to comment.