1
|
|
2
|
|
3
|
|
4
|
module CommandTestHelper
|
5
|
|
6
|
def with_params(params, &block)
|
7
|
context "with params "+params.to_s do
|
8
|
let(:with_params) { params }
|
9
|
self.instance_eval(&block)
|
10
|
end
|
11
|
end
|
12
|
|
13
|
def it_should_call_action(action, params)
|
14
|
it "should call action " + action.to_s do
|
15
|
arguments ||= respond_to?(:with_params) ? with_params : []
|
16
|
cmd.resource.resource_class.expects_with(action, params)
|
17
|
cmd.run(arguments)
|
18
|
end
|
19
|
end
|
20
|
|
21
|
def it_should_fail_with(message, arguments=[])
|
22
|
it "should fail with " + message.to_s do
|
23
|
proc { cmd.run(arguments) }.must_raise Clamp::UsageError
|
24
|
end
|
25
|
end
|
26
|
|
27
|
def it_should_accept(message, arguments=[])
|
28
|
it "should accept " + message.to_s do
|
29
|
cmd.run(arguments).must_equal HammerCLI::EX_OK
|
30
|
end
|
31
|
end
|
32
|
|
33
|
def it_should_print_column(column_name, arguments=nil)
|
34
|
it "should print column " + column_name do
|
35
|
arguments ||= respond_to?(:with_params) ? with_params : []
|
36
|
|
37
|
cmd.stubs(:context).returns({ :adapter => :test })
|
38
|
proc { cmd.run(arguments) }.must_output /.*##{column_name}#.*/
|
39
|
end
|
40
|
end
|
41
|
|
42
|
def it_should_print_columns(column_names, arguments=nil)
|
43
|
column_names.each do |name|
|
44
|
it_should_print_column name, arguments
|
45
|
end
|
46
|
end
|
47
|
|
48
|
def it_should_print_n_records(count=nil, arguments=nil)
|
49
|
it "should print correct count of records" do
|
50
|
arguments ||= respond_to?(:with_params) ? with_params : []
|
51
|
|
52
|
cmd.stubs(:context).returns({ :adapter => :test })
|
53
|
count ||= expected_record_count rescue 0
|
54
|
out, err = capture_io do
|
55
|
cmd.run(arguments)
|
56
|
end
|
57
|
|
58
|
out.split(/\n/).length.must_equal count+1
|
59
|
end
|
60
|
end
|
61
|
|
62
|
def it_should_accept_search_params
|
63
|
it_should_accept "search", ["--search=some_search"]
|
64
|
it_should_accept "per page", ["--per-page=1"]
|
65
|
it_should_accept "page", ["--page=2"]
|
66
|
it_should_accept "order", ["--order=order"]
|
67
|
end
|
68
|
|
69
|
end
|