forked from amuraru/itunes-connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_spec.rb
78 lines (67 loc) · 2.54 KB
/
report_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe AppStore::Commands::Report do
before(:each) do
@cmd = AppStore::Commands::Report.new(mock(:null_object => true))
end
describe 'with valid execution arguments' do
before(:each) do
@store = mock(AppStore::Store)
AppStore::Store.should_receive(:new).
with("/tmp/store.db").
and_return(@store)
@io = StringIO.new
@data = [
mock(:report_date => Date.parse('2009/09/09'), :country => 'US',
:install_count => 1, :update_count => 2),
mock(:report_date => Date.parse('2009/09/09'), :country => 'GB',
:install_count => 3, :update_count => 4)
]
end
it 'should request counts with no options with no qualifiers' do
@store.should_receive(:counts).and_return(@data)
clip = stub(:db => '/tmp/store.db', :group? => false, :null_object => true)
@cmd.execute!(clip, [], @io)
@io.string.should == "2009-09-09\tUS\t1\t2\n" +
"2009-09-09\tGB\t3\t4\n"
end
it 'should output data with other options' do
@store.should_receive(:counts).
with(:to => Date.parse('2009/09/09'),
:from => Date.parse('2009/09/01'),
:country => 'US').
and_return(@data)
clip = stub(:db => '/tmp/store.db',
:group? => false,
:to => Date.parse('2009/09/09'),
:from => Date.parse('2009/09/01'),
:country => 'US')
@cmd.execute!(clip, [], @io)
@io.string.should == "2009-09-09\tUS\t1\t2\n" +
"2009-09-09\tGB\t3\t4\n"
end
end
describe 'with :group option specified' do
before(:each) do
@store = mock(AppStore::Store)
AppStore::Store.should_receive(:new).
with('/tmp/store.db').
and_return(@store)
@io = StringIO.new
@data = [
mock(:country => 'US', :install_count => 1, :update_count => 2),
mock(:country => 'GB', :install_count => 3, :update_count => 4)
]
end
it 'should request grouped country data' do
@store.should_receive(:country_counts).and_return(@data)
clip = stub(:db => '/tmp/store.db', :group? => true, :null_object => true)
@cmd.execute!(clip, [], @io)
@io.string.should == "US\t1\t2\nGB\t3\t4\n"
end
end
describe 'with invalid execution arguments' do
it 'should require the :db option' do
lambda { @cmd.execute! }.should raise_error(ArgumentError)
end
end
end