Skip to content

Commit e7838f7

Browse files
committed
Merge pull request #394 from pixeltrix/fix-warnings
Fix warnings when running specs with `$VERBOSE = true`
2 parents 7d00ea4 + bf8b022 commit e7838f7

16 files changed

+84
-71
lines changed

.rspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--color
1+
-w --color

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ rvm:
1010
- 1.9.2
1111
- 1.9.3
1212
- 2.0.0
13+
- 2.1.0
1314
- rbx
1415
- ruby-head
1516
matrix:

lib/thor.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ def package_name(name, options = {})
1919
# meth<Symbol>:: name of the default command
2020
#
2121
def default_command(meth = nil)
22-
@default_command = case meth
23-
when :none
24-
'help'
25-
when nil
26-
@default_command || from_superclass(:default_command, 'help')
27-
else
28-
meth.to_s
29-
end
22+
if meth
23+
@default_command = meth == :none ? 'help' : meth.to_s
24+
else
25+
@default_command ||= from_superclass(:default_command, 'help')
26+
end
3027
end
3128
alias_method :default_task, :default_command
3229

@@ -195,7 +192,7 @@ def help(shell, subcommand = false)
195192
end
196193
list.sort! { |a, b| a[0] <=> b[0] }
197194

198-
if @package_name
195+
if defined?(@package_name) && @package_name
199196
shell.say "#{@package_name} commands:"
200197
else
201198
shell.say 'Commands:'
@@ -310,15 +307,17 @@ def check_unknown_options?(config) #:nodoc:
310307
# ==== Parameters
311308
# Symbol ...:: A list of commands that should be affected.
312309
def stop_on_unknown_option!(*command_names)
313-
@stop_on_unknown_option ||= Set.new
314-
@stop_on_unknown_option.merge(command_names)
310+
stop_on_unknown_option.merge(command_names)
315311
end
316312

317313
def stop_on_unknown_option?(command) #:nodoc:
318-
command && !@stop_on_unknown_option.nil? && @stop_on_unknown_option.include?(command.name.to_sym)
314+
command && stop_on_unknown_option.include?(command.name.to_sym)
319315
end
320316

321317
protected
318+
def stop_on_unknown_option #:nodoc:
319+
@stop_on_unknown_option ||= Set.new
320+
end
322321

323322
# The method responsible for dispatching given the args.
324323
def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable MethodLength
@@ -382,6 +381,10 @@ def dynamic_command_class #:nodoc:
382381
end
383382

384383
def create_command(meth) #:nodoc:
384+
@usage ||= nil
385+
@desc ||= nil
386+
@long_desc ||= nil
387+
385388
if @usage && @desc
386389
base_class = @hide ? Thor::HiddenCommand : Thor::Command
387390
commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)

lib/thor/actions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def source_paths
2828
# Stores and return the source root for this class
2929
def source_root(path = nil)
3030
@_source_root = path if path
31-
@_source_root
31+
@_source_root ||= nil
3232
end
3333

3434
# Returns the source paths in the following order:

lib/thor/base.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,11 @@ def remove_class_option(*names)
317317
# name<String|Symbol>
318318
#
319319
def group(name = nil)
320-
@group = case name
321-
when nil
322-
@group || from_superclass(:group, 'standard')
323-
else
324-
name.to_s
325-
end
320+
if name
321+
@group = name.to_s
322+
else
323+
@group ||= from_superclass(:group, 'standard')
324+
end
326325
end
327326

328327
# Returns the commands for this Thor class.
@@ -592,6 +591,7 @@ def method_added(meth)
592591
# Return if it's not a public instance method
593592
return unless public_method_defined?(meth.to_sym)
594593

594+
@no_commands ||= false
595595
return if @no_commands || !create_command(meth)
596596

597597
is_thor_reserved_word?(meth, :command)

lib/thor/core_ext/ordered_hash.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def []=(key, value)
2828
else
2929
node = Node.new(key, value)
3030

31-
if @first.nil?
31+
if !defined?(@first) || @first.nil?
3232
@first = @last = node
3333
else
3434
node.prev = @last
@@ -68,7 +68,7 @@ def values
6868
end
6969

7070
def each
71-
return unless @first
71+
return unless defined?(@first) && @first
7272
yield [@first.key, @first.value]
7373
node = @first
7474
yield [node.key, node.value] while node = node.next # rubocop:disable AssignmentInCondition

lib/thor/group.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ class << self
1414
# description<String>:: The description for this Thor::Group.
1515
#
1616
def desc(description = nil)
17-
@desc = case description
18-
when nil
19-
@desc || from_superclass(:desc, nil)
20-
else
21-
description
22-
end
17+
if description
18+
@desc = description
19+
else
20+
@desc ||= from_superclass(:desc, nil)
21+
end
2322
end
2423

2524
# Prints help information.

lib/thor/line_editor/readline.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def use_path_completion?
4848
end
4949

5050
class PathCompletion
51+
attr_reader :text
52+
private :text
53+
5154
def initialize(text)
5255
@text = text
5356
end
@@ -58,8 +61,6 @@ def matches
5861

5962
private
6063

61-
attr_reader :text
62-
6364
def relative_matches
6465
absolute_matches.map { |path| path.sub(base_path, '') }
6566
end

lib/thor/shell/basic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Basic # rubocop:disable ClassLength
99
# Initialize base, mute and padding to nil.
1010
#
1111
def initialize #:nodoc:
12-
@base, @mute, @padding = nil, false, 0
12+
@base, @mute, @padding, @always_force = nil, false, 0, false
1313
end
1414

1515
# Mute everything that's inside given block

spec/actions/create_file_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
describe Thor::Actions::CreateFile do
55
before do
6+
@silence = false
67
::FileUtils.rm_rf(destination_root)
78
end
89

@@ -29,13 +30,13 @@ def silence!
2930
it 'creates a file' do
3031
create_file('doc/config.rb')
3132
invoke!
32-
expect(File.exists?(File.join(destination_root, 'doc/config.rb'))).to be true
33+
expect(File.exist?(File.join(destination_root, 'doc/config.rb'))).to be true
3334
end
3435

3536
it 'does not create a file if pretending' do
3637
create_file('doc/config.rb', {}, :pretend => true)
3738
invoke!
38-
expect(File.exists?(File.join(destination_root, 'doc/config.rb'))).to be false
39+
expect(File.exist?(File.join(destination_root, 'doc/config.rb'))).to be false
3940
end
4041

4142
it 'shows created status to the user' do
@@ -58,7 +59,7 @@ def silence!
5859
it 'converts encoded instructions' do
5960
create_file('doc/%file_name%.rb.tt')
6061
invoke!
61-
expect(File.exists?(File.join(destination_root, 'doc/rdoc.rb.tt'))).to be true
62+
expect(File.exist?(File.join(destination_root, 'doc/rdoc.rb.tt'))).to be true
6263
end
6364

6465
describe 'when file exists' do
@@ -137,13 +138,13 @@ def silence!
137138
create_file('doc/config.rb')
138139
invoke!
139140
revoke!
140-
expect(File.exists?(@action.destination)).to be false
141+
expect(File.exist?(@action.destination)).to be false
141142
end
142143

143144
it 'does not raise an error if the file does not exist' do
144145
create_file('doc/config.rb')
145146
revoke!
146-
expect(File.exists?(@action.destination)).to be false
147+
expect(File.exist?(@action.destination)).to be false
147148
end
148149
end
149150

0 commit comments

Comments
 (0)