-
Notifications
You must be signed in to change notification settings - Fork 0
/
every_day_irb_spec.rb
122 lines (91 loc) · 2.53 KB
/
every_day_irb_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
require_relative '../lib/every_day_irb'
require 'fileutils'
describe EveryDayIrb do
include EveryDayIrb
let(:filename){ __FILE__ }
let(:filename_without_rb){ filename.sub(/\.rb$/, '') }
let(:path){ File.dirname(filename) + '/..' }
describe '#ls' do
it 'returns an array' do
expect( ls ).to be_a Array
end
context '[no args]' do
it 'calls Dir["./*"] to get the list of all files in the current dir' do
res = Dir['./*']
expect( Dir ).to receive(:[]).with('./*').and_return(res)
ls
end
end
context 'one arg' do
it 'calls Dir["#{path}/*"] to get the list of all files of the given path' do
res = Dir["#{path}/*"]
expect( Dir ).to receive(:[]).with("#{path}/*").and_return(res)
ls(path)
end
end
end
describe "#cd" do
it 'returns an array' do
expect( ls ).to be_a Array
end
it 'requests FileUtils to change the directory' do
expect( FileUtils::Verbose ).to receive(:cd).with("/")
cd "/"
end
end
describe '#cat' do
it 'returns a String' do
expect( cat(filename) ).to be_a String
end
it 'calls File.read(path)' do
expect( File ).to receive(:read).with(filename)
cat(filename)
end
end
describe '#rq' do
it 'calls require with the arg' do
expect( self ).to receive(:require).with('rbconfig')
rq 'rbconfig'
end
it 'calls to_s on the arg' do
expect( self ).to receive(:require).with('rbconfig')
rq:rbconfig
end
end
describe '#rr' do
it 'calls require_re with the arg' do
expect( self ).to receive(:require_relative).with('something').and_return(nil)
rr 'something'
end
it 'calls to_s on the arg' do
expect( self ).to receive(:require_relative).with('something').and_return(nil)
rr:something
end
end
describe '#ld' do
it 'calls load with the arg, but appends ".rb"' do
expect( self ).to receive(:load).with(filename)
ld filename_without_rb
end
it 'calls to_s on the arg' do
expect( self ).to receive(:load).with(filename)
ld filename_without_rb.to_sym
end
end
describe '#rerequire' do
it 'requires a library a second time' do
first_time = require 'abbrev'
second_time = rerequire 'abbrev'
expect( second_time ).to be true
end
end
describe '#clear' do
it "calls the system's clear command" do
expect( self ).to receive(:system).with('clear')
clear
end
end
describe '#reset!' do
pending
end
end