forked from tenderlove/geera
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4039769
commit d84fc25
Showing
4 changed files
with
126 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Geera | ||
module Commands | ||
class List < Geera::Commands::Command | ||
def self.handle? command | ||
'list' == command | ||
end | ||
|
||
def number | ||
## Ensure that +number+ is actually a number | ||
begin | ||
@number = Integer(super) | ||
rescue ArgumentError | ||
@number = geera.filters.find { |f| f.name == super }.id | ||
end | ||
end | ||
|
||
def execute! | ||
tickets = geera.list number | ||
if tickets.empty? | ||
puts "No Tickets found" | ||
else | ||
tickets.first(10).each do |ticket| | ||
puts "#{ticket.key.ljust(8)} #{ticket.summary}" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require "test/unit" | ||
require "geera" | ||
require 'flexmock/test_unit' | ||
|
||
module Geera | ||
module Commands | ||
class TestList < Test::Unit::TestCase | ||
FakeTicket = Struct.new(:key, :summary) | ||
|
||
def test_handle? | ||
assert List.handle?('list') | ||
end | ||
|
||
def test_number_with_name | ||
recorder = Object.new | ||
flexmock(recorder) do |thing| | ||
thing.should_receive(:filters).once.and_return( | ||
[Struct.new(:name, :id).new('foo', 10)] | ||
) | ||
end | ||
|
||
cmd = List.new(nil, 'foo', recorder, []) | ||
assert_equal 10, cmd.number | ||
end | ||
|
||
def test_number | ||
recorder = Object.new | ||
flexmock(recorder) do |thing| | ||
thing.should_receive(:filters).never | ||
end | ||
|
||
cmd = List.new(nil, 10, recorder, []) | ||
assert_equal 10, cmd.number | ||
end | ||
|
||
def test_execute! | ||
number = 10 | ||
|
||
recorder = Object.new | ||
flexmock(recorder) do |thing| | ||
thing.should_receive(:list).with(number).once.and_return([ | ||
FakeTicket.new('BZ-123', 'hello'), | ||
FakeTicket.new('BZ-124', 'world'), | ||
]) | ||
end | ||
|
||
cmd = Class.new(List) { | ||
attr_reader :putses | ||
def initialize *args | ||
super | ||
@putses = [] | ||
end | ||
|
||
def puts string | ||
@putses << string | ||
end | ||
}.new(nil, number, recorder, []) | ||
|
||
cmd.execute! | ||
assert_match(/BZ-123/, cmd.putses.first) | ||
assert_match(/hello/, cmd.putses.first) | ||
assert_match(/BZ-124/, cmd.putses[1]) | ||
assert_match(/world/, cmd.putses[1]) | ||
end | ||
|
||
def test_empty_execute | ||
recorder = Object.new | ||
flexmock(recorder) do |thing| | ||
thing.should_receive(:list).with(10).once.and_return([]) | ||
end | ||
|
||
cmd = Class.new(List) { | ||
attr_reader :putses | ||
def initialize *args | ||
super | ||
@putses = [] | ||
end | ||
|
||
def puts string | ||
@putses << string | ||
end | ||
}.new(nil, 10, recorder, []) | ||
cmd.execute! | ||
|
||
assert_equal ["No Tickets found"], cmd.putses | ||
end | ||
end | ||
end | ||
end | ||
|