Skip to content

Commit

Permalink
Merge pull request #9 from nathanstitt/no_default_printer
Browse files Browse the repository at this point in the history
No default printer
  • Loading branch information
m0wfo committed Jul 14, 2013
2 parents a0d33f5 + fd623d8 commit ac3ec46
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
3 changes: 2 additions & 1 deletion ext/cups.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ static VALUE cups_get_default(VALUE self)
VALUE def_p = rb_str_new2(default_printer);

return def_p;
} else {
return Qnil;
}
// should return nil if no default printer is found!
}

/*
Expand Down
54 changes: 26 additions & 28 deletions test/cups_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,75 +20,73 @@ def test_same_printers_returned
assert cups_destinations.is_a?(Array)
assert_equal cups_destinations, lplist
end

def test_can_instantiate_print_job_object_with_correct_args
assert_raise(ArgumentError) do
Cups::PrintJob.new
end

assert_nothing_raised do
Cups::PrintJob.new("/path", @printer)
Cups::PrintJob.new("/path")
Cups::PrintJob.new("/path") if Cups.default_printer
end
end

def test_job_defaults_to_default
assert_nothing_raised do
pj = Cups::PrintJob.new("/non/existent/file")

assert_equal Cups.default_printer, pj.instance_variable_get(:@printer)
if Cups.default_printer
pj = Cups::PrintJob.new( "/non/existent/file" )
assert_equal Cups.default_printer, pj.instance_variable_get(:@printer)
end
end
end

def test_we_cant_print_to_nonexistent_printers
assert_raise(RuntimeError) do
assert_raise(ArgumentError) do
pj = Cups::PrintJob.new("/non/existent/file", "bollocks_printer")

assert !Cups.show_destinations.include?(pj.instance_variable_get(:@printer))
end
end

def test_we_cant_print_nonexistent_files
pj = Cups::PrintJob.new("soft_class")

pj = Cups::PrintJob.new("soft_class",@printer)
assert_raise(RuntimeError) do
pj.print
pj.print
end

assert_nil pj.job_id
end

def test_we_can_pass_args_down_as_options
options = {:foo => 'bar'}
pj = Cups::PrintJob.new(sample, @printer, options)
assert_equal(options, pj.job_options)
end

def test_we_can_only_pass_strings_down_as_options
options = {:foo => 'bar'}
pj = Cups::PrintJob.new(sample, @printer, options)
assert_raise(TypeError) { pj.print }
end

def test_we_can_omit_options_and_will_set_to_empty
pj = Cups::PrintJob.new(sample, @printer)
assert_equal({}, pj.job_options)
end

def test_print_job_cancellation
pj = Cups::PrintJob.new(sample, @printer)
pj.print
assert_not_nil pj.job_id
assert_equal pj.cancel, true
assert pj.job_id.is_a?(Fixnum)
end

def test_all_jobs_raises_with_nonexistent_printers
assert_raise(RuntimeError) { Cups.all_jobs(nil) }
end

def test_all_jobs_returns_hash
assert Cups.all_jobs(Cups.default_printer).is_a?(Hash)
assert Cups.all_jobs(@printer).is_a?(Hash)
end

def test_all_jobs_hash_contains_info_hash
Expand All @@ -98,11 +96,11 @@ def test_all_jobs_hash_contains_info_hash
assert info.is_a?(Hash)
assert info.keys.all?{|key| [:title, :format, :submitted_by, :state, :size].include?(key)}
end

def test_dest_list_returns_array
assert Cups.show_destinations.is_a?(Array)
end

def test_dest_options_returns_hash_if_real
assert Cups.options_for(@printer).is_a?(Hash)
end
Expand All @@ -128,7 +126,7 @@ def test_job_title
end

def test_returns_failure_string_on_cancellation
pj = Cups::PrintJob.new(blank_sample, @printer)
pj = Cups::PrintJob.new(sample, @printer)
pj.print

# assert pj.job_id == 0 # Failed jobs have an ID of zero
Expand All @@ -148,20 +146,20 @@ def test_job_state_string
assert pj.state == :cancelled
assert !pj.completed?
end

def test_print_job_attributes
pj = Cups::PrintJob.new(sample)
pj = Cups::PrintJob.new(sample, @printer)
[:printer, :filename, :job_id].each do |attr|
assert pj.respond_to?(attr)
end
end

private

def sample
"#{File.dirname(__FILE__)}/sample.txt"
end

def blank_sample
"#{File.dirname(__FILE__)}/sample_blank.txt"
end
Expand Down

0 comments on commit ac3ec46

Please sign in to comment.