-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathmethods_spec.rb
63 lines (50 loc) · 1.57 KB
/
methods_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
# frozen_string_literal: true
require 'spec_helper'
require 'commander/methods'
describe Commander::Methods do
it 'includes Commander::UI' do
expect(subject.ancestors).to include(Commander::UI)
end
describe 'AskForClass' do
it 'includes Commander::UI::AskForClass' do
expect(subject.ancestors).to include(Commander::UI::AskForClass)
end
describe 'defining methods' do
let(:terminal) { double }
before do
allow(terminal).to receive(:ask)
@old_highline = HighLine.default_instance
HighLine.default_instance = terminal
end
after do
HighLine.default_instance = @old_highline
end
subject do
Class.new do
include Commander::UI::AskForClass
end.new
end
it 'defines common "ask_for_*" methods' do
expect(subject.respond_to?(:ask_for_float)).to be_truthy
end
it 'responds to "ask_for_*" methods for classes that implement #parse' do
expect(subject.respond_to?(:ask_for_datetime)).to be_truthy
end
it 'fails "ask_for_*" method invocations without a prompt' do
expect do
subject.ask_for_datetime
end.to raise_error(ArgumentError)
end
it 'implements "ask_for_*"' do
expect(terminal).to receive(:ask)
subject.ask_for_datetime('hi')
end
end
end
it 'includes Commander::Delegates' do
expect(subject.ancestors).to include(Commander::Delegates)
end
it 'does not change the Object ancestors' do
expect(Object.ancestors).not_to include(Commander::UI)
end
end