thor 0.12.2 → 0.12.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,81 +17,81 @@ describe Thor::Shell::Basic do
17
17
 
18
18
  describe "#ask" do
19
19
  it "prints a message to the user and gets the response" do
20
- mock($stdout).print("Should I overwrite it? ")
21
- mock($stdin).gets{ "Sure" }
20
+ $stdout.should_receive(:print).with("Should I overwrite it? ")
21
+ $stdin.should_receive(:gets).and_return('Sure')
22
22
  shell.ask("Should I overwrite it?").must == "Sure"
23
23
  end
24
24
  end
25
25
 
26
26
  describe "#yes?" do
27
27
  it "asks the user and returns true if the user replies yes" do
28
- mock($stdout).print("Should I overwrite it? ")
29
- mock($stdin).gets{ "y" }
28
+ $stdout.should_receive(:print).with("Should I overwrite it? ")
29
+ $stdin.should_receive(:gets).and_return('y')
30
30
  shell.yes?("Should I overwrite it?").must be_true
31
31
 
32
- mock($stdout).print("Should I overwrite it? ")
33
- mock($stdin).gets{ "n" }
32
+ $stdout.should_receive(:print).with("Should I overwrite it? ")
33
+ $stdin.should_receive(:gets).and_return('n')
34
34
  shell.yes?("Should I overwrite it?").must_not be_true
35
35
  end
36
36
  end
37
37
 
38
38
  describe "#no?" do
39
39
  it "asks the user and returns true if the user replies no" do
40
- mock($stdout).print("Should I overwrite it? ")
41
- mock($stdin).gets{ "n" }
40
+ $stdout.should_receive(:print).with("Should I overwrite it? ")
41
+ $stdin.should_receive(:gets).and_return('n')
42
42
  shell.no?("Should I overwrite it?").must be_true
43
43
 
44
- mock($stdout).print("Should I overwrite it? ")
45
- mock($stdin).gets{ "Yes" }
44
+ $stdout.should_receive(:print).with("Should I overwrite it? ")
45
+ $stdin.should_receive(:gets).and_return('Yes')
46
46
  shell.no?("Should I overwrite it?").must be_false
47
47
  end
48
48
  end
49
49
 
50
50
  describe "#say" do
51
51
  it "prints a message to the user" do
52
- mock($stdout).puts("Running...")
52
+ $stdout.should_receive(:puts).with("Running...")
53
53
  shell.say("Running...")
54
54
  end
55
55
 
56
56
  it "prints a message to the user without new line if it ends with a whitespace" do
57
- mock($stdout).print("Running... ")
57
+ $stdout.should_receive(:print).with("Running... ")
58
58
  shell.say("Running... ")
59
59
  end
60
60
 
61
61
  it "prints a message to the user without new line" do
62
- mock($stdout).print("Running...")
62
+ $stdout.should_receive(:print).with("Running...")
63
63
  shell.say("Running...", nil, false)
64
64
  end
65
65
  end
66
66
 
67
67
  describe "#say_status" do
68
68
  it "prints a message to the user with status" do
69
- mock($stdout).puts(" create ~/.thor/task.thor")
69
+ $stdout.should_receive(:puts).with(" create ~/.thor/task.thor")
70
70
  shell.say_status(:create, "~/.thor/task.thor")
71
71
  end
72
72
 
73
73
  it "always use new line" do
74
- mock($stdout).puts(" create ")
74
+ $stdout.should_receive(:puts).with(" create ")
75
75
  shell.say_status(:create, "")
76
76
  end
77
77
 
78
78
  it "does not print a message if base is set to quiet" do
79
79
  base = MyCounter.new [1,2]
80
- mock(base).options { Hash.new(:quiet => true) }
80
+ base.should_receive(:options).and_return(:quiet => true)
81
81
 
82
- dont_allow($stdout).puts
82
+ $stdout.should_not_receive(:puts)
83
83
  shell.base = base
84
84
  shell.say_status(:created, "~/.thor/task.thor")
85
85
  end
86
86
 
87
87
  it "does not print a message if log status is set to false" do
88
- dont_allow($stdout).puts
88
+ $stdout.should_not_receive(:puts)
89
89
  shell.say_status(:created, "~/.thor/task.thor", false)
90
90
  end
91
91
 
92
92
  it "uses padding to set messages left margin" do
93
93
  shell.padding = 2
94
- mock($stdout).puts(" create ~/.thor/task.thor")
94
+ $stdout.should_receive(:puts).with(" create ~/.thor/task.thor")
95
95
  shell.say_status(:create, "~/.thor/task.thor")
96
96
  end
97
97
  end
@@ -123,7 +123,7 @@ TABLE
123
123
  end
124
124
 
125
125
  it "uses maximum terminal width" do
126
- mock(shell).terminal_width { 20 }
126
+ shell.should_receive(:terminal_width).and_return(20)
127
127
  content = capture(:stdout){ shell.print_table(@table, :ident => 2, :truncate => true) }
128
128
  content.must == <<-TABLE
129
129
  abc #123 firs...
@@ -135,41 +135,41 @@ TABLE
135
135
 
136
136
  describe "#file_collision" do
137
137
  it "shows a menu with options" do
138
- mock($stdout).print('Overwrite foo? (enter "h" for help) [Ynaqh] ')
139
- mock($stdin).gets{ 'n' }
138
+ $stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
139
+ $stdin.should_receive(:gets).and_return('n')
140
140
  shell.file_collision('foo')
141
141
  end
142
142
 
143
143
  it "returns true if the user choose default option" do
144
- stub($stdout).print
145
- mock($stdin).gets{ '' }
144
+ $stdout.stub!(:print)
145
+ $stdin.should_receive(:gets).and_return('')
146
146
  shell.file_collision('foo').must be_true
147
147
  end
148
148
 
149
149
  it "returns false if the user choose no" do
150
- stub($stdout).print
151
- mock($stdin).gets{ 'n' }
150
+ $stdout.stub!(:print)
151
+ $stdin.should_receive(:gets).and_return('n')
152
152
  shell.file_collision('foo').must be_false
153
153
  end
154
154
 
155
155
  it "returns true if the user choose yes" do
156
- stub($stdout).print
157
- mock($stdin).gets{ 'y' }
156
+ $stdout.stub!(:print)
157
+ $stdin.should_receive(:gets).and_return('y')
158
158
  shell.file_collision('foo').must be_true
159
159
  end
160
160
 
161
161
  it "shows help usage if the user choose help" do
162
- stub($stdout).print
163
- mock($stdin).gets{ 'h' }
164
- mock($stdin).gets{ 'n' }
162
+ $stdout.stub!(:print)
163
+ $stdin.should_receive(:gets).and_return('h')
164
+ $stdin.should_receive(:gets).and_return('n')
165
165
  help = capture(:stdout){ shell.file_collision('foo') }
166
166
  help.must =~ /h \- help, show this help/
167
167
  end
168
168
 
169
169
  it "quits if the user choose quit" do
170
- stub($stdout).print
171
- mock($stdout).puts('Aborting...')
172
- mock($stdin).gets{ 'q' }
170
+ $stdout.stub!(:print)
171
+ $stdout.should_receive(:puts).with('Aborting...')
172
+ $stdin.should_receive(:gets).and_return('q')
173
173
 
174
174
  lambda {
175
175
  shell.file_collision('foo')
@@ -177,27 +177,27 @@ TABLE
177
177
  end
178
178
 
179
179
  it "always returns true if the user choose always" do
180
- mock($stdout).print('Overwrite foo? (enter "h" for help) [Ynaqh] ')
181
- mock($stdin).gets{ 'a' }
180
+ $stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
181
+ $stdin.should_receive(:gets).and_return('a')
182
182
 
183
183
  shell.file_collision('foo').must be_true
184
184
 
185
- dont_allow($stdout).print
185
+ $stdout.should_not_receive(:print)
186
186
  shell.file_collision('foo').must be_true
187
187
  end
188
188
 
189
189
  describe "when a block is given" do
190
190
  it "displays diff options to the user" do
191
- mock($stdout).print('Overwrite foo? (enter "h" for help) [Ynaqdh] ')
192
- mock($stdin).gets{ 's' }
191
+ $stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqdh] ')
192
+ $stdin.should_receive(:gets).and_return('s')
193
193
  shell.file_collision('foo'){ }
194
194
  end
195
195
 
196
196
  it "invokes the diff command" do
197
- stub($stdout).print
198
- mock($stdin).gets{ 'd' }
199
- mock($stdin).gets{ 'n' }
200
- mock(shell).system(/diff -u/)
197
+ $stdout.stub!(:print)
198
+ $stdin.should_receive(:gets).and_return('d')
199
+ $stdin.should_receive(:gets).and_return('n')
200
+ shell.should_receive(:system).with(/diff -u/)
201
201
  capture(:stdout){ shell.file_collision('foo'){ } }
202
202
  end
203
203
  end
@@ -7,19 +7,19 @@ describe Thor::Shell::Color do
7
7
 
8
8
  describe "#say" do
9
9
  it "set the color if specified" do
10
- mock($stdout).puts("\e[32mWow! Now we have colors!\e[0m")
10
+ $stdout.should_receive(:puts).with("\e[32mWow! Now we have colors!\e[0m")
11
11
  shell.say "Wow! Now we have colors!", :green
12
12
  end
13
13
 
14
14
  it "does not use a new line even with colors" do
15
- mock($stdout).print("\e[32mWow! Now we have colors! \e[0m")
15
+ $stdout.should_receive(:print).with("\e[32mWow! Now we have colors! \e[0m")
16
16
  shell.say "Wow! Now we have colors! ", :green
17
17
  end
18
18
  end
19
19
 
20
20
  describe "#say_status" do
21
21
  it "uses color to say status" do
22
- mock($stdout).puts("\e[1m\e[31m conflict\e[0m README")
22
+ $stdout.should_receive(:puts).with("\e[1m\e[31m conflict\e[0m README")
23
23
  shell.say_status :conflict, "README", :red
24
24
  end
25
25
  end
@@ -27,9 +27,9 @@ describe Thor::Shell::Color do
27
27
  describe "#file_collision" do
28
28
  describe "when a block is given" do
29
29
  it "invokes the diff command" do
30
- stub($stdout).print
31
- mock($stdin).gets{ 'd' }
32
- mock($stdin).gets{ 'n' }
30
+ $stdout.stub!(:print)
31
+ $stdin.should_receive(:gets).and_return('d')
32
+ $stdin.should_receive(:gets).and_return('n')
33
33
 
34
34
  output = capture(:stdout){ shell.file_collision('spec/fixtures/doc/README'){ "README\nEND\n" } }
35
35
  output.must =~ /\e\[31m\- __start__\e\[0m/
@@ -5,9 +5,11 @@ require 'thor'
5
5
  require 'stringio'
6
6
 
7
7
  require 'rubygems'
8
- require 'rr'
8
+ require 'rdoc'
9
9
  require 'diff/lcs' # You need diff/lcs installed to run specs (but not to run Thor).
10
10
 
11
+ $thor_runner = true
12
+
11
13
  # Load fixtures
12
14
  load File.join(File.dirname(__FILE__), "fixtures", "task.thor")
13
15
  load File.join(File.dirname(__FILE__), "fixtures", "group.thor")
@@ -25,8 +27,6 @@ Kernel.module_eval do
25
27
  end
26
28
 
27
29
  Spec::Runner.configure do |config|
28
- config.mock_with :rr
29
-
30
30
  def capture(stream)
31
31
  begin
32
32
  stream = stream.to_s
@@ -48,5 +48,5 @@ Spec::Runner.configure do |config|
48
48
  File.join(File.dirname(__FILE__), 'sandbox')
49
49
  end
50
50
 
51
- alias silence capture
51
+ alias :silence :capture
52
52
  end
@@ -11,20 +11,20 @@ describe Thor::Task do
11
11
 
12
12
  describe "#formatted_usage" do
13
13
  it "includes namespace within usage" do
14
- stub(Object).namespace{ "foo" }
15
- stub(Object).arguments{ [] }
14
+ Object.stub!(:namespace).and_return("foo")
15
+ Object.stub!(:arguments).and_return([])
16
16
  task(:bar => :required).formatted_usage(Object).must == "foo:can_has --bar=BAR"
17
17
  end
18
18
 
19
19
  it "removes default from namespace" do
20
- stub(Object).namespace{ "default:foo" }
21
- stub(Object).arguments{ [] }
20
+ Object.stub!(:namespace).and_return("default:foo")
21
+ Object.stub!(:arguments).and_return([])
22
22
  task(:bar => :required).formatted_usage(Object).must == ":foo:can_has --bar=BAR"
23
23
  end
24
24
 
25
25
  it "injects arguments into usage" do
26
- stub(Object).namespace{ "foo" }
27
- stub(Object).arguments{ [ Thor::Argument.new(:bar, nil, true, :string) ] }
26
+ Object.stub!(:namespace).and_return("foo")
27
+ Object.stub!(:arguments).and_return([ Thor::Argument.new(:bar, nil, true, :string) ])
28
28
  task(:foo => :required).formatted_usage(Object).must == "foo:can_has BAR --foo=FOO"
29
29
  end
30
30
  end
@@ -54,15 +54,17 @@ describe Thor::Task do
54
54
 
55
55
  describe "#run" do
56
56
  it "runs a task by calling a method in the given instance" do
57
- mock = mock!.send("can_has", 1, 2, 3).subject
57
+ mock = mock()
58
+ mock.should_receive(:send).with("can_has", 1, 2, 3)
58
59
  task.run(mock, [1, 2, 3])
59
60
  end
60
61
 
61
62
  it "raises an error if the method to be invoked is private" do
62
- mock = mock!.private_methods{ [ 'can_has' ] }.subject
63
+ mock = mock()
64
+ mock.should_receive(:private_methods).and_return(['can_has'])
63
65
  lambda {
64
66
  task.run(mock)
65
- }.must raise_error(Thor::UndefinedTaskError, "the 'can_has' task of Object is private")
67
+ }.must raise_error(Thor::UndefinedTaskError, "the 'can_has' task of Spec::Mocks::Mock is private")
66
68
  end
67
69
  end
68
70
  end
@@ -156,9 +156,9 @@ describe Thor do
156
156
  end
157
157
 
158
158
  it "uses the maximum terminal size to show tasks" do
159
- mock(@shell).terminal_width { 80 }
160
- @content = capture(:stdout){ MyScript.help(shell) }
161
- @content.must =~ /aaa\.\.\.$/
159
+ @shell.should_receive(:terminal_width).and_return(80)
160
+ content = capture(:stdout){ MyScript.help(shell) }
161
+ content.must =~ /aaa\.\.\.$/
162
162
  end
163
163
 
164
164
  it "provides description for tasks from classes in the same namespace" do
@@ -184,7 +184,7 @@ describe Thor do
184
184
 
185
185
  describe "for a specific task" do
186
186
  it "provides full help info when talking about a specific task" do
187
- capture(:stdout) { MyScript.help(shell, :task => "foo") }.must == <<END
187
+ capture(:stdout) { MyScript.task_help(shell, "foo") }.must == <<END
188
188
  Usage:
189
189
  thor my_script:foo BAR
190
190
 
@@ -199,21 +199,18 @@ END
199
199
 
200
200
  it "raises an error if the task can't be found" do
201
201
  lambda {
202
- MyScript.help(shell, :task => "unknown")
202
+ MyScript.task_help(shell, "unknown")
203
203
  }.must raise_error(Thor::Error, "task 'unknown' could not be found in namespace 'my_script'")
204
204
  end
205
205
  end
206
206
 
207
- describe "options" do
208
- it "does not show superclass tasks if required" do
209
- capture(:stdout){ MyScript.help(shell, :short => true) }.must_not =~ /help/
207
+ describe "instance method" do
208
+ it "calls the class method" do
209
+ capture(:stdout){ MyScript.start(["help"]) }.must =~ /Tasks:/
210
210
  end
211
- end
212
211
 
213
- describe "instance method" do
214
212
  it "calls the class method" do
215
- stub(MyScript).help(mock.instance_of(Thor::Base.shell), :task => nil)
216
- MyScript.start(["help"])
213
+ capture(:stdout){ MyScript.start(["help", "foo"]) }.must =~ /Usage:/
217
214
  end
218
215
  end
219
216
  end
@@ -129,7 +129,7 @@ describe Thor::Util do
129
129
 
130
130
  describe "#user_home" do
131
131
  before(:each) do
132
- stub(ENV)[]
132
+ ENV.stub!(:[])
133
133
  Thor::Util.clear_user_home!
134
134
  end
135
135
 
@@ -138,7 +138,7 @@ describe Thor::Util do
138
138
  end
139
139
 
140
140
  it "returns the *unix system path if file cannot be expanded and separator does not exist" do
141
- stub(File).expand_path("~"){ raise }
141
+ File.should_receive(:expand_path).with("~").and_raise(RuntimeError)
142
142
  previous_value = File::ALT_SEPARATOR
143
143
  capture(:stderr){ File.const_set(:ALT_SEPARATOR, false) }
144
144
  Thor::Util.user_home.must == "/"
@@ -146,7 +146,7 @@ describe Thor::Util do
146
146
  end
147
147
 
148
148
  it "returns the windows system path if file cannot be expanded and a separator exists" do
149
- stub(File).expand_path("~"){ raise }
149
+ File.should_receive(:expand_path).with("~").and_raise(RuntimeError)
150
150
  previous_value = File::ALT_SEPARATOR
151
151
  capture(:stderr){ File.const_set(:ALT_SEPARATOR, true) }
152
152
  Thor::Util.user_home.must == "C:/"
@@ -154,43 +154,19 @@ describe Thor::Util do
154
154
  end
155
155
 
156
156
  it "returns HOME/.thor if set" do
157
- stub(ENV)["HOME"].returns{ "/home/user/" }
157
+ ENV.stub!(:[]).with("HOME").and_return("/home/user/")
158
158
  Thor::Util.user_home.must == "/home/user/"
159
159
  end
160
160
 
161
161
  it "returns path with HOMEDRIVE and HOMEPATH if set" do
162
- stub(ENV)["HOMEDRIVE"].returns{ "D:/" }
163
- stub(ENV)["HOMEPATH"].returns{ "Documents and Settings/James" }
162
+ ENV.stub!(:[]).with("HOMEDRIVE").and_return("D:/")
163
+ ENV.stub!(:[]).with("HOMEPATH").and_return("Documents and Settings/James")
164
164
  Thor::Util.user_home.must == "D:/Documents and Settings/James"
165
165
  end
166
166
 
167
167
  it "returns APPDATA/.thor if set" do
168
- stub(ENV)["APPDATA"].returns{ "/home/user/" }
168
+ ENV.stub!(:[]).with("APPDATA").and_return("/home/user/")
169
169
  Thor::Util.user_home.must == "/home/user/"
170
170
  end
171
171
  end
172
-
173
- describe "#convert_constants_to_namespaces" do
174
- before(:each) do
175
- @hash = {
176
- :git => {
177
- :constants => [Object, "Thor::Sandbox::Package", Thor::CoreExt::OrderedHash]
178
- }
179
- }
180
- end
181
-
182
- it "converts constants in the hash to namespaces" do
183
- Thor::Util.convert_constants_to_namespaces(@hash)
184
- @hash[:git][:namespaces].must == [ "object", "package", "thor:core_ext:ordered_hash" ]
185
- end
186
-
187
- it "returns true if the hash changed" do
188
- Thor::Util.convert_constants_to_namespaces(@hash).must be_true
189
- end
190
-
191
- it "does not add namespaces to the hash if namespaces were already added" do
192
- Thor::Util.convert_constants_to_namespaces(@hash)
193
- Thor::Util.convert_constants_to_namespaces(@hash).must be_false
194
- end
195
- end
196
172
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-01 00:00:00 +01:00
13
+ date: 2010-01-18 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -41,6 +41,7 @@ files:
41
41
  - lib/thor/actions/file_manipulation.rb
42
42
  - lib/thor/actions/inject_into_file.rb
43
43
  - lib/thor/base.rb
44
+ - lib/thor/core_ext/file_binary_read.rb
44
45
  - lib/thor/core_ext/hash_with_indifferent_access.rb
45
46
  - lib/thor/core_ext/ordered_hash.rb
46
47
  - lib/thor/error.rb
@@ -115,38 +116,11 @@ test_files:
115
116
  - spec/task_spec.rb
116
117
  - spec/thor_spec.rb
117
118
  - spec/util_spec.rb
118
- - spec/actions/create_file_spec.rb
119
- - spec/actions/directory_spec.rb
120
- - spec/actions/empty_directory_spec.rb
121
- - spec/actions/file_manipulation_spec.rb
122
- - spec/actions/inject_into_file_spec.rb
123
- - spec/actions_spec.rb
124
- - spec/base_spec.rb
125
- - spec/core_ext/hash_with_indifferent_access_spec.rb
126
- - spec/core_ext/ordered_hash_spec.rb
127
- - spec/fixtures/application.rb
128
- - spec/fixtures/bundle/execute.rb
129
119
  - spec/fixtures/bundle/main.thor
130
120
  - spec/fixtures/doc/%file_name%.rb.tt
131
- - spec/fixtures/doc/config.rb
132
121
  - spec/fixtures/doc/README
133
122
  - spec/fixtures/group.thor
134
123
  - spec/fixtures/invoke.thor
135
124
  - spec/fixtures/script.thor
136
125
  - spec/fixtures/task.thor
137
- - spec/group_spec.rb
138
- - spec/invocation_spec.rb
139
- - spec/parser/argument_spec.rb
140
- - spec/parser/arguments_spec.rb
141
- - spec/parser/option_spec.rb
142
- - spec/parser/options_spec.rb
143
- - spec/rake_compat_spec.rb
144
- - spec/runner_spec.rb
145
- - spec/shell/basic_spec.rb
146
- - spec/shell/color_spec.rb
147
- - spec/shell_spec.rb
148
126
  - spec/spec.opts
149
- - spec/spec_helper.rb
150
- - spec/task_spec.rb
151
- - spec/thor_spec.rb
152
- - spec/util_spec.rb