Skip to content

Commit 3ba8d62

Browse files
committedFeb 24, 2017
Include RuboCop
1 parent ffdb7af commit 3ba8d62

14 files changed

+334
-188
lines changed
 

‎.rubocop.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
inherit_from: .rubocop_rspec_base.yml
2+
3+
# Relax some metric cops for now. All of these should be removed eventually.
4+
5+
AbcSize:
6+
Max: 40
7+
8+
BlockLength:
9+
Max: 180
10+
11+
ClassLength:
12+
Max: 130
13+
14+
LineLength:
15+
Max: 150
16+
17+
MethodLength:
18+
Max: 50
19+
20+
ModuleLength:
21+
Max: 160
22+
23+
PerceivedComplexity:
24+
Max: 12

‎.rubocop_rspec_base.yml

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Source: https://raw.githubusercontent.com/rspec/rspec-dev/master/travis/.rubocop_rspec_base.yml
2+
# Downloaded on 2017-02-24, adapted to current Rubocop versions (`Style/TrailingComma` no longer exists).
3+
4+
# This file contains defaults for RSpec projects. Individual projects
5+
# can customize by inheriting this file and overriding particular settings.
6+
7+
AccessModifierIndentation:
8+
EnforcedStyle: outdent
9+
10+
# "Use alias_method instead of alias"
11+
# We're fine with `alias`.
12+
Alias:
13+
Enabled: false
14+
15+
AlignParameters:
16+
EnforcedStyle: with_first_parameter
17+
18+
# "Avoid the use of the case equality operator ==="
19+
# We prefer using `Class#===` over `Object#is_a?` because `Class#===`
20+
# is less likely to be monkey patched than `is_a?` on a user object.
21+
CaseEquality:
22+
Enabled: false
23+
24+
# Warns when the class is excessively long.
25+
ClassLength:
26+
Max: 100
27+
28+
CollectionMethods:
29+
PreferredMethods:
30+
reduce: 'inject'
31+
32+
# Over time we'd like to get this down, but this is what we're at now.
33+
CyclomaticComplexity:
34+
Max: 10
35+
36+
# We use YARD to enforce documentation. It works better than rubocop's
37+
# enforcement...rubocop complains about the places we re-open
38+
# `RSpec::Expectations` and `RSpec::Matchers` w/o having doc commments.
39+
Documentation:
40+
Enabled: false
41+
42+
# We still support 1.8.7 which requires trailing dots
43+
DotPosition:
44+
EnforcedStyle: trailing
45+
46+
DoubleNegation:
47+
Enabled: false
48+
49+
# each_with_object is unavailable on 1.8.7 so we have to disable this one.
50+
EachWithObject:
51+
Enabled: false
52+
53+
Encoding:
54+
EnforcedStyle: when_needed
55+
56+
FormatString:
57+
EnforcedStyle: percent
58+
59+
# As long as we support ruby 1.8.7 we have to use hash rockets.
60+
HashSyntax:
61+
EnforcedStyle: hash_rockets
62+
63+
# We can't use the new lambda syntax, since we still support 1.8.7.
64+
Lambda:
65+
Enabled: false
66+
67+
# Over time we'd like to get this down, but this is what we're at now.
68+
LineLength:
69+
Max: 100
70+
71+
# Over time we'd like to get this down, but this is what we're at now.
72+
MethodLength:
73+
Max: 15
74+
75+
# Who cares what we call the argument for binary operator methods?
76+
OpMethod:
77+
Enabled: false
78+
79+
PercentLiteralDelimiters:
80+
PreferredDelimiters:
81+
'%': () # double-quoted string
82+
'%i': '[]' # array of symbols
83+
'%q': () # single-quoted string
84+
'%Q': () # double-quoted string
85+
'%r': '{}' # regular expression pattern
86+
'%s': () # a symbol
87+
'%w': '[]' # array of single-quoted strings
88+
'%W': '[]' # array of double-quoted strings
89+
'%x': () # a shell command as a string
90+
91+
# We have too many special cases where we allow generator methods or prefer a
92+
# prefixed predicate due to it's improved readability.
93+
PredicateName:
94+
Enabled: false
95+
96+
# On 1.8 `proc` is `lambda`, so we use `Proc.new` to ensure we get real procs on all supported versions.
97+
# http://batsov.com/articles/2014/02/04/the-elements-of-style-in-ruby-number-12-proc-vs-proc-dot-new/
98+
Proc:
99+
Enabled: false
100+
101+
RedundantReturn:
102+
AllowMultipleReturnValues: true
103+
104+
# Exceptions should be rescued with `Support::AllExceptionsExceptOnesWeMustNotRescue`
105+
RescueException:
106+
Enabled: true
107+
108+
# We haven't adopted the `fail` to signal exceptions vs `raise` for re-raises convention.
109+
SignalException:
110+
Enabled: false
111+
112+
# We've tended to use no space, so it's less of a change to stick with that.
113+
SpaceAroundEqualsInParameterDefault:
114+
EnforcedStyle: no_space
115+
116+
# We don't care about single vs double qoutes.
117+
StringLiterals:
118+
Enabled: false
119+
120+
# This rule favors constant names from the English standard library which we don't load.
121+
Style/SpecialGlobalVars:
122+
Enabled: false
123+
124+
Style/TrailingCommaInArguments:
125+
Enabled: false
126+
127+
Style/TrailingCommaInLiteral:
128+
Enabled: false
129+
130+
TrivialAccessors:
131+
AllowDSLWriters: true
132+
AllowPredicates: true
133+
ExactNameMatch: true

‎Support/lib/rspec/mate/gutter_marks.rb

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ module RSpec
55
module Mate
66
class GutterMarks
77
include Helpers
8-
9-
MARK = "warning"
8+
9+
MARK = "warning".freeze
1010
SpecError = Struct.new(:line, :message)
1111

1212
attr_reader :errors_by_path
@@ -26,14 +26,14 @@ def set_marks
2626
end
2727
end
2828

29-
private
29+
private
3030

3131
def clear_marks_for(path)
3232
run_mate("--clear-mark=#{MARK}", path)
3333
end
3434

3535
def set_mark_for(path, line, message)
36-
message = message.strip.gsub("\n", "\r")
36+
message = message.strip.tr("\n", "\r")
3737
run_mate("--set-mark=#{MARK}:#{message}", "--line=#{line}", path)
3838
end
3939

@@ -46,13 +46,12 @@ def extract_data_from(examples)
4646
@errors_by_path = {}
4747
examples.each do |example|
4848
@errors_by_path[example.file_path] ||= []
49-
if example.execution_result.status == :failed && example.location =~ /:(\d+)$/
50-
line = $1
51-
message = example.exception ? example.exception.message : "(no exception message)"
52-
@errors_by_path[example.file_path] << SpecError.new(line, message)
53-
end
49+
next unless example.execution_result.status == :failed && example.location =~ /:(\d+)$/
50+
line = Regexp.last_match(1)
51+
message = example.exception ? example.exception.message : "(no exception message)"
52+
@errors_by_path[example.file_path] << SpecError.new(line, message)
5453
end
5554
end
5655
end
5756
end
58-
end
57+
end

‎Support/lib/rspec/mate/helpers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ def base_dir
66
end
77
end
88
end
9-
end
9+
end

‎Support/lib/rspec/mate/runner.rb

+27-33
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,32 @@ module RSpec
99
module Mate
1010
class Runner
1111
include Helpers
12-
LAST_REMEMBERED_FILE_CACHE = "/tmp/textmate_rspec_last_remembered_file_cache.txt"
13-
LAST_RUN_CACHE = "/tmp/textmate_rspec_last_run.yml"
14-
12+
LAST_REMEMBERED_FILE_CACHE = "/tmp/textmate_rspec_last_remembered_file_cache.txt".freeze
13+
LAST_RUN_CACHE = "/tmp/textmate_rspec_last_run.yml".freeze
14+
1515
def run_files(options={})
1616
files = ENV['TM_SELECTED_FILES'] ? Shellwords.shellwords(ENV['TM_SELECTED_FILES']) : ["spec/"]
17-
options.merge!({:files => files})
17+
options[:files] = files
1818
run(options)
1919
end
2020

2121
def run_file(options={})
22-
options.merge!({:files => [single_file]})
22+
options[:files] = [single_file]
2323
run(options)
2424
end
2525

2626
def run_last_remembered_file(options={})
27-
options.merge!({:files => [last_remembered_single_file]})
27+
options[:files] = [last_remembered_single_file]
2828
run(options)
2929
end
3030

3131
def run_again
3232
run(:run_again => true)
3333
end
34-
34+
3535
def run_focussed(options={})
36-
options.merge!(
37-
{
38-
:files => [single_file],
39-
:line => ENV['TM_LINE_NUMBER']
40-
}
41-
)
36+
options[:files] = [single_file]
37+
options[:line] = ENV['TM_LINE_NUMBER']
4238

4339
run(options)
4440
end
@@ -52,29 +48,29 @@ def run(options)
5248
end
5349
run_rspec(argv)
5450
end
55-
51+
5652
def run_rspec(argv)
5753
stderr = StringIO.new
5854
old_stderr = $stderr
5955
$stderr = stderr
6056

6157
Dir.chdir(project_directory) do
62-
cmd =
58+
cmd =
6359
if use_binstub?
64-
%w(bin/rspec) + argv
60+
%w[bin/rspec] + argv
6561
elsif gemfile?
66-
%w(bundle exec rspec) + argv
62+
%w[bundle exec rspec] + argv
6763
else
68-
%w(rspec) + argv
64+
%w[rspec] + argv
6965
end
70-
Open3.popen3(*cmd) do |i, out, err, thread|
66+
Open3.popen3(*cmd) do |i, out, err, _thread|
7167
i.close
7268
stderr_thread = Thread.new do
73-
while (line = err.gets) do
69+
while (line = err.gets)
7470
stderr.puts line
7571
end
7672
end
77-
while (line = out.gets) do
73+
while (line = out.gets)
7874
$stdout.puts line
7975
$stdout.flush
8076
end
@@ -85,7 +81,7 @@ def run_rspec(argv)
8581
unless stderr.string == ""
8682
$stdout <<
8783
"<pre class='stderr'>" <<
88-
CGI.escapeHTML(stderr.string) <<
84+
CGI.escapeHTML(stderr.string) <<
8985
"</pre>"
9086
end
9187

@@ -106,12 +102,12 @@ def gemfile?
106102
def use_binstub?
107103
File.exist?(File.join(base_dir, 'bin', 'rspec'))
108104
end
109-
105+
110106
private
111107

112108
def build_argv_from_options(options)
113109
default_formatter = 'RSpec::Mate::Formatters::TextMateFormatter'
114-
formatter = ENV['TM_RSPEC_FORMATTER'] || default_formatter
110+
formatter = ENV['TM_RSPEC_FORMATTER'] || default_formatter
115111

116112
# If :line is given, only the first file from :files is used. This should be ok though, because
117113
# :line is only ever set in #run_focussed, and there :files is always set to a single file only.
@@ -121,19 +117,15 @@ def build_argv_from_options(options)
121117
argv << '-r' << File.join(File.dirname(__FILE__), 'text_mate_formatter') if formatter == 'RSpec::Mate::Formatters::TextMateFormatter'
122118
argv << '-r' << File.join(File.dirname(__FILE__), 'filter_bundle_backtrace')
123119

124-
if ENV['TM_RSPEC_OPTS']
125-
argv += ENV['TM_RSPEC_OPTS'].split(" ")
126-
end
127-
120+
argv += ENV['TM_RSPEC_OPTS'].split(" ") if ENV['TM_RSPEC_OPTS']
121+
128122
argv
129123
end
130-
124+
131125
def last_remembered_single_file
132126
file = File.read(LAST_REMEMBERED_FILE_CACHE).strip
133127

134-
if file.size > 0
135-
File.expand_path(file)
136-
end
128+
File.expand_path(file) unless file.empty?
137129
end
138130

139131
def save_as_last_run(args)
@@ -147,7 +139,9 @@ def load_argv_from_last_run
147139
end
148140

149141
def project_directory
150-
File.expand_path(base_dir) rescue File.dirname(single_file)
142+
File.expand_path(base_dir)
143+
rescue
144+
File.dirname(single_file)
151145
end
152146

153147
def single_file

‎Support/lib/rspec/mate/snippet_extractor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SnippetExtractor
1111
# @private
1212
class NullConverter
1313
def convert(code)
14-
%Q(#{code}\n<span class="comment"># Install the coderay gem to get syntax highlighting</span>)
14+
%(#{code}\n<span class="comment"># Install the coderay gem to get syntax highlighting</span>)
1515
end
1616
end
1717

‎Support/lib/rspec/mate/switch_command.rb

+63-63
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ def go_to_twin(project_directory, filepath)
1212
other = twin(filepath)
1313

1414
if File.file?(other)
15-
%x{ "$TM_SUPPORT_PATH/bin/mate" "#{other}" }
15+
`"$TM_SUPPORT_PATH/bin/mate" "#{other}"`
1616
else
17-
relative = other[project_directory.length+1..-1]
17+
relative = other[project_directory.length + 1..-1]
1818
file_type = file_type(other)
1919

20-
if create?(relative, file_type)
21-
write_and_open(other)
22-
end
20+
write_and_open(other) if create?(relative, file_type)
2321
end
2422
end
2523

@@ -38,59 +36,59 @@ def rails?
3836
end
3937

4038
def twin(path)
41-
if path =~ /^(.*?)\/(lib|app|spec)\/(.*?)$/
42-
framework, parent, rest = $1, $2, $3
43-
framework.extend Framework
44-
45-
case parent
46-
when 'lib', 'app' then
47-
if framework.merb_or_rails?
48-
if path.include?("/app/lib/")
49-
path = path.gsub("/app/lib/", "/spec/app/lib/")
50-
else
51-
path = path.gsub(/\/app\//, "/spec/")
52-
path = path.gsub(/\/lib\//, "/spec/lib/")
53-
end
54-
else
55-
path = path.gsub(/\/lib\//, "/spec/")
56-
end
57-
58-
path = path.gsub(/\.rb$/, "_spec.rb")
59-
path = path.gsub(/\.erb$/, ".erb_spec.rb")
60-
path = path.gsub(/\.haml$/, ".haml_spec.rb")
61-
path = path.gsub(/\.slim$/, ".slim_spec.rb")
62-
path = path.gsub(/\.rhtml$/, ".rhtml_spec.rb")
63-
path = path.gsub(/\.rjs$/, ".rjs_spec.rb")
64-
when 'spec' then
65-
path = path.gsub(/\.rjs_spec\.rb$/, ".rjs")
66-
path = path.gsub(/\.rhtml_spec\.rb$/, ".rhtml")
67-
path = path.gsub(/\.erb_spec\.rb$/, ".erb")
68-
path = path.gsub(/\.haml_spec\.rb$/, ".haml")
69-
path = path.gsub(/\.slim_spec\.rb$/, ".slim")
70-
path = path.gsub(/_spec\.rb$/, ".rb")
71-
72-
if framework.merb_or_rails?
73-
if path.include?("/spec/app/lib/")
74-
path = path.gsub("/spec/app/lib/", "/app/lib/")
75-
else
76-
path = path.gsub(/\/spec\/lib\//, "/lib/")
77-
path = path.gsub(/\/spec\//, "/app/")
78-
end
79-
else
80-
path = path.gsub(/\/spec\//, "/lib/")
81-
end
39+
return unless path =~ %r{^(.*?)/(lib|app|spec)/(.*?)$}
40+
framework = Regexp.last_match(1)
41+
parent = Regexp.last_match(2)
42+
framework.extend Framework
43+
44+
case parent
45+
when 'lib', 'app' then
46+
if framework.merb_or_rails?
47+
if path.include?("/app/lib/")
48+
path = path.gsub("/app/lib/", "/spec/app/lib/")
49+
else
50+
path = path.gsub(%r{/app/}, "/spec/")
51+
path = path.gsub(%r{/lib/}, "/spec/lib/")
52+
end
53+
else
54+
path = path.gsub(%r{/lib/}, "/spec/")
8255
end
8356

84-
return path
57+
path = path.gsub(/\.rb$/, "_spec.rb")
58+
path = path.gsub(/\.erb$/, ".erb_spec.rb")
59+
path = path.gsub(/\.haml$/, ".haml_spec.rb")
60+
path = path.gsub(/\.slim$/, ".slim_spec.rb")
61+
path = path.gsub(/\.rhtml$/, ".rhtml_spec.rb")
62+
path = path.gsub(/\.rjs$/, ".rjs_spec.rb")
63+
when 'spec' then
64+
path = path.gsub(/\.rjs_spec\.rb$/, ".rjs")
65+
path = path.gsub(/\.rhtml_spec\.rb$/, ".rhtml")
66+
path = path.gsub(/\.erb_spec\.rb$/, ".erb")
67+
path = path.gsub(/\.haml_spec\.rb$/, ".haml")
68+
path = path.gsub(/\.slim_spec\.rb$/, ".slim")
69+
path = path.gsub(/_spec\.rb$/, ".rb")
70+
71+
if framework.merb_or_rails?
72+
if path.include?("/spec/app/lib/")
73+
path = path.gsub("/spec/app/lib/", "/app/lib/")
74+
else
75+
path = path.gsub(%r{/spec/lib/}, "/lib/")
76+
path = path.gsub(%r{/spec/}, "/app/")
77+
end
78+
else
79+
path = path.gsub(%r{/spec/}, "/lib/")
80+
end
8581
end
82+
83+
path
8684
end
8785

8886
def file_type(path)
8987
case path
90-
when /^(.*?)\/(spec)\/(controllers|helpers|models|views)\/(.*?)$/
91-
"#{$3[0..-2]} spec"
92-
when /^(.*?)\/(app)\/(controllers|helpers|models|views)\/(.*?)$/
93-
$3[0..-2]
88+
when %r{^(.*?)/(spec)/(controllers|helpers|models|views)/(.*?)$}
89+
"#{Regexp.last_match(3)[0..-2]} spec"
90+
when %r{^(.*?)/(app)/(controllers|helpers|models|views)/(.*?)$}
91+
Regexp.last_match(3)[0..-2]
9492
when /_spec\.rb$/
9593
"spec"
9694
else
@@ -99,7 +97,10 @@ def file_type(path)
9997
end
10098

10199
def create?(relative_twin, file_type)
102-
answer = `'#{ ENV['TM_SUPPORT_PATH'] }/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog' yesno-msgbox --no-cancel --icon document --informative-text "#{relative_twin}" --text "Create missing #{file_type}?"`
100+
cmd = %('#{ENV['TM_SUPPORT_PATH']}/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog') +
101+
%(yesno-msgbox --no-cancel --icon document --informative-text "#{relative_twin}") +
102+
%(--text "Create missing #{file_type}?")
103+
answer = `#{cmd}`
103104
answer.to_s.chomp == "1"
104105
end
105106

@@ -113,22 +114,22 @@ def class_from_path(path)
113114
end
114115
end
115116

116-
def klass(relative_path, content=nil)
117+
def klass(relative_path, _content=nil)
117118
parts = relative_path.split('/')
118119
lib_index = parts.index('lib') || 0
119-
parts = parts[lib_index+1..-1]
120-
lines = Array.new(parts.length*2)
120+
parts = parts[lib_index + 1..-1]
121+
lines = Array.new(parts.length * 2)
121122

122123
parts.each_with_index do |part, n|
123124
part = part.capitalize
124125
indent = " " * n
125126

126127
line = if part =~ /(.*)\.rb/
127-
part = $1
128-
"#{indent}class #{part}"
129-
else
130-
"#{indent}module #{part}"
131-
end
128+
part = Regexp.last_match(1)
129+
"#{indent}class #{part}"
130+
else
131+
"#{indent}module #{part}"
132+
end
132133

133134
lines[n] = line
134135
lines[lines.length - (n + 1)] = "#{indent}end"
@@ -148,12 +149,12 @@ def write_and_open(path)
148149
f.puts ' ' # <= caret will be here
149150
f.puts 'end'
150151
end
151-
system ENV['TM_SUPPORT_PATH']+'/bin/mate', path, '-l4:3'
152+
system ENV['TM_SUPPORT_PATH'] + '/bin/mate', path, '-l4:3'
152153
end
153154

154155
def described_class_for(path, base_path)
155156
relative_path = path[base_path.size..-1]
156-
camelize = lambda {|part| part.gsub(/_([a-z])/){$1.upcase}.gsub(/^([a-z])/){$1.upcase}}
157+
camelize = lambda { |part| part.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }.gsub(/^([a-z])/) { Regexp.last_match(1).upcase } }
157158
parts = File.dirname(relative_path).split('/').compact.reject(&:empty?)
158159
parts.shift if parts[0] == 'app'
159160
parts.shift if parts[0] == 'spec' && %w[controllers helpers models views].include?(parts[1])
@@ -164,6 +165,5 @@ def described_class_for(path, base_path)
164165
described
165166
end
166167
end
167-
168168
end
169169
end

‎Support/lib/rspec/mate/text_mate_backtrace_printer.rb

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
module RSpec
77
module Mate
88
module Formatters
9+
# rubocop:disable ClassLength,LineLength
910
class TextMateBacktracePrinter
1011
include ERB::Util # for the #h method
1112
def initialize(output)
@@ -51,9 +52,9 @@ def print_example_passed(description, run_time)
5152
@output.puts " <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(description)}</span><span class='duration'>#{formatted_run_time}s</span></dd>"
5253
end
5354

54-
# rubocop:disable Style/ParameterLists
55-
def print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace=false)
56-
# rubocop:enable Style/ParameterLists
55+
# rubocop:disable Metrics/ParameterLists
56+
def print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, _escape_backtrace=false)
57+
# rubocop:enable Metrics/ParameterLists
5758
formatted_run_time = "%.5f" % run_time
5859
backtrace = make_backtrace_clickable(exception[:backtrace])
5960

@@ -120,8 +121,10 @@ def make_example_group_header_yellow(group_id)
120121

121122
def make_backtrace_clickable(backtrace)
122123
backtrace.gsub!(/(^.*?):(\d+):(.*)/) do
123-
path, line, rest = $1, $2, $3
124-
url = "txmt://open?url=file://#{CGI::escape(File.expand_path(path))}&line=#{$2}"
124+
path = Regexp.last_match(1)
125+
line = Regexp.last_match(2)
126+
rest = Regexp.last_match(3)
127+
url = "txmt://open?url=file://#{CGI.escape(File.expand_path(path))}&line=#{Regexp.last_match(2)}"
125128
link_text = "#{path}:#{line}"
126129
"<a href='#{CGI.escape_html(url)}'>#{CGI.escape_html(link_text)}</a>:#{CGI.escape_html(rest)}"
127130
end
@@ -131,7 +134,7 @@ def indentation_style(number_of_parents)
131134
"style=\"margin-left: #{(number_of_parents - 1) * 15}px;\""
132135
end
133136

134-
REPORT_HEADER = <<-EOF
137+
REPORT_HEADER = <<-EOF.freeze
135138
<div class="rspec-report">
136139
<div id="rspec-header">
137140
<div id="rspec-progress-wrap"><div id="rspec-progress"></div></div>
@@ -156,7 +159,7 @@ def indentation_style(number_of_parents)
156159
<div class="results">
157160
EOF
158161

159-
GLOBAL_SCRIPTS = <<-EOF
162+
GLOBAL_SCRIPTS = <<-EOF.freeze
160163
161164
function addClass(element_id, classname) {
162165
document.getElementById(element_id).className += (" " + classname);
@@ -239,10 +242,10 @@ def indentation_style(number_of_parents)
239242
}
240243
EOF
241244

242-
GLOBAL_STYLES = <<-EOF
245+
GLOBAL_STYLES = <<-EOF.freeze
243246
#rspec-header {
244247
position: relative;
245-
color: #fff;
248+
color: #fff;
246249
height: 4em;
247250
}
248251
@@ -437,7 +440,7 @@ def indentation_style(number_of_parents)
437440
}
438441
EOF
439442

440-
HTML_HEADER = <<-EOF
443+
HTML_HEADER = <<-EOF.freeze
441444
<!DOCTYPE html>
442445
<html lang='en'>
443446
<head>

‎Support/lib/rspec/mate/text_mate_formatter.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ module Mate
1212
module Formatters
1313
class TextMateFormatter < ::RSpec::Core::Formatters::BaseFormatter
1414
::RSpec::Core::Formatters.register self, :message, :seed, :start, :example_group_started, :start_dump,
15-
:example_started, :example_passed, :example_failed,
16-
:example_pending, :dump_summary
15+
:example_started, :example_passed, :example_failed,
16+
:example_pending, :dump_summary
1717

1818
def initialize(output)
1919
super(output)
@@ -97,7 +97,7 @@ def example_failed(failure)
9797
example.execution_result.run_time,
9898
@failed_examples.size,
9999
exception_details,
100-
(extra == "") ? false : extra,
100+
extra == "" ? false : extra,
101101
true
102102
)
103103
@printer.flush
@@ -143,7 +143,7 @@ def example_number
143143
def percent_done
144144
result = 100.0
145145
if @example_count > 0
146-
result = (((example_number).to_f / @example_count.to_f * 1000).to_i / 10.0).to_f
146+
result = ((example_number.to_f / @example_count.to_f * 1000).to_i / 10.0).to_f
147147
end
148148
result
149149
end

‎Support/spec/rspec/mate/gutter_marks_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'rspec/mate/gutter_marks'
33

44
describe RSpec::Mate::GutterMarks do
5-
let(:example_group){ RSpec.describe("example group") }
5+
let(:example_group) { RSpec.describe("example group") }
66

77
def example_with_location(path, line, &block)
88
example_group.example('example', &block).tap do |ex|
@@ -12,9 +12,9 @@ def example_with_location(path, line, &block)
1212
end
1313

1414
it 'runs `mate` with the appropriate arguments', :sandboxed do
15-
example_with_location('./foo/successes.rb', 5){ }
16-
example_with_location('./foo/failures.rb', 12){ raise "a failed example" }
17-
example_with_location('./foo/failures.rb', 24){ raise "another failure" }
15+
example_with_location('./foo/successes.rb', 5) {}
16+
example_with_location('./foo/failures.rb', 12) { raise "a failed example" }
17+
example_with_location('./foo/failures.rb', 24) { raise "another failure" }
1818
example_group.run
1919
gm = RSpec::Mate::GutterMarks.new(example_group.examples)
2020
expect(gm).to receive(:run_mate).with("--clear-mark=warning", "./foo/successes.rb")

‎Support/spec/rspec/mate/runner_spec.rb

+38-39
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ def capture
1313
ensure
1414
$stdout = original_stdout
1515
end
16-
16+
1717
before(:each) do
1818
# TODO: long path
19-
@first_failing_spec = /fixtures\/example_failing_spec\.rb:3/n
20-
@second_failing_spec = /fixtures\/example_failing_spec\.rb:7/n
19+
@first_failing_spec = %r{fixtures/example_failing_spec\.rb:3}n
20+
@second_failing_spec = %r{fixtures/example_failing_spec\.rb:7}n
2121

2222
@original_env = ENV.to_hash
2323
set_env
@@ -27,10 +27,10 @@ def capture
2727
"#{File.dirname(__FILE__)}/../../../lib/rspec/mate.rb"
2828
)
2929

30-
# Make sure we dont overwrite the real files when running the examples here
30+
# Make sure we don't overwrite the "real" files when running the examples here
3131
stub_const("RSpec::Mate::Runner::LAST_RUN_CACHE", "/tmp/textmate_rspec_last_run.test.yml")
3232
stub_const("RSpec::Mate::Runner::LAST_REMEMBERED_FILE_CACHE", "/tmp/textmate_rspec_last_remembered_file_cache.test.txt")
33-
33+
3434
@spec_mate = RSpec::Mate::Runner.new
3535
end
3636

@@ -46,17 +46,17 @@ def capture
4646
it "shows standard error output nicely in a PRE block" do
4747
ENV['TM_FILEPATH'] = fixtures_path('example_stderr_spec.rb')
4848

49-
html = capture{ @spec_mate.run_file }
49+
html = capture { @spec_mate.run_file }
5050

51-
expect(html).to match /#{Regexp.escape("<pre class='stderr'>2 + 2 = 4\n4 &lt; 8\n</pre>")}/
51+
expect(html).to match(/#{Regexp.escape("<pre class='stderr'>2 + 2 = 4\n4 &lt; 8\n</pre>")}/)
5252
end
5353
end
5454

5555
describe "#run_file" do
5656
it "runs whole file when only file specified" do
5757
ENV['TM_FILEPATH'] = fixtures_path('example_failing_spec.rb')
5858

59-
html = capture{ @spec_mate.run_file }
59+
html = capture { @spec_mate.run_file }
6060

6161
expect(html).to match @first_failing_spec
6262
expect(html).to match @second_failing_spec
@@ -71,14 +71,14 @@ def capture
7171
]
7272

7373
# TODO: adjust fixtures_path to take an array
74-
ENV['TM_SELECTED_FILES'] = Shellwords.join(fixtures.map{ |fixture| fixtures_path(fixture) })
74+
ENV['TM_SELECTED_FILES'] = Shellwords.join(fixtures.map { |fixture| fixtures_path(fixture) })
7575

76-
html = capture{ @spec_mate.run_files }
76+
html = capture { @spec_mate.run_files }
7777

7878
expect(html).to match @first_failing_spec
7979
expect(html).to match @second_failing_spec
80-
expect(html).to match /should pass/
81-
expect(html).to match /should pass too/
80+
expect(html).to match(/should pass/)
81+
expect(html).to match(/should pass too/)
8282
end
8383

8484
it 'runs all examples in "spec/" if nothing is selected' do
@@ -93,7 +93,7 @@ def capture
9393
describe "#run_last_remembered_file" do
9494
it "runs all of the selected files" do
9595
@spec_mate.save_as_last_remembered_file fixtures_path('example_failing_spec.rb')
96-
html = capture{ @spec_mate.run_last_remembered_file }
96+
html = capture { @spec_mate.run_last_remembered_file }
9797

9898
expect(html).to match @first_failing_spec
9999
end
@@ -102,7 +102,8 @@ def capture
102102
describe '#run_again' do
103103
def self.it_works_for(method, &block)
104104
it "works for #{method}" do
105-
original_argv, rerun_argv = nil, nil
105+
original_argv = nil
106+
rerun_argv = nil
106107
expect(@spec_mate).to receive(:run_rspec) do |argv|
107108
original_argv = argv.dup
108109
end
@@ -115,17 +116,17 @@ def self.it_works_for(method, &block)
115116
expect(rerun_argv).to eq original_argv
116117
end
117118
end
118-
119+
119120
it_works_for '#run_file' do
120121
ENV['TM_FILEPATH'] = fixtures_path('example_failing_spec.rb')
121122
@spec_mate.run_file
122123
end
123-
124+
124125
it_works_for '#run_files' do
125126
ENV['TM_SELECTED_FILES'] = "foo/bar_spec.rb baz/baz/baz/baz_spec.rb"
126127
@spec_mate.run_files
127128
end
128-
129+
129130
it_works_for '#run_focused' do
130131
ENV['TM_FILEPATH'] = fixtures_path('example_failing_spec.rb')
131132
ENV['TM_LINE_NUMBER'] = '4'
@@ -138,7 +139,7 @@ def self.it_works_for(method, &block)
138139
ENV['TM_FILEPATH'] = fixtures_path('example_failing_spec.rb')
139140
ENV['TM_LINE_NUMBER'] = '4'
140141

141-
html = capture{ @spec_mate.run_focussed }
142+
html = capture { @spec_mate.run_focussed }
142143

143144
expect(html).to match @first_failing_spec
144145
expect(html).to_not match @second_failing_spec
@@ -148,7 +149,7 @@ def self.it_works_for(method, &block)
148149
ENV['TM_FILEPATH'] = fixtures_path('example_failing_spec.rb')
149150
ENV['TM_LINE_NUMBER'] = '8'
150151

151-
html = capture{ @spec_mate.run_focussed }
152+
html = capture { @spec_mate.run_focussed }
152153

153154
expect(html).to_not match @first_failing_spec
154155
expect(html).to match @second_failing_spec
@@ -160,63 +161,62 @@ def self.it_works_for(method, &block)
160161
ENV['TM_RSPEC_FORMATTER'] = 'RSpec::Core::Formatters::BaseTextFormatter'
161162
ENV['TM_FILEPATH'] = fixtures_path('example_failing_spec.rb')
162163

163-
text = capture{ @spec_mate.run_file }
164+
text = capture { @spec_mate.run_file }
164165

165-
expect(text).to match /1\) An example failing spec should fail/
166-
expect(text).to match /2\) An example failing spec should also fail/
166+
expect(text).to match(/1\) An example failing spec should fail/)
167+
expect(text).to match(/2\) An example failing spec should also fail/)
167168
end
168169
end
169170

170171
describe '#run_rspec' do
171172
def expect_rspec_to_be_run_as(cmd)
172173
expect(Open3).to receive(:popen3).with(*cmd)
173174
end
174-
175+
175176
context 'with Gemfile.lock' do
176177
it 'uses `bundle exec rspec`' do
177178
ENV["TM_PROJECT_DIRECTORY"] = fixtures_path("project_with_gemfile")
178-
expect_rspec_to_be_run_as(%w(bundle exec rspec some args))
179-
@spec_mate.run_rspec(%w(some args))
179+
expect_rspec_to_be_run_as(%w[bundle exec rspec some args])
180+
@spec_mate.run_rspec(%w[some args])
180181
end
181182
end
182-
183+
183184
context 'without Gemfile.lock' do
184185
it 'uses `bin/rspec`, if a binstub is present' do
185186
ENV["TM_PROJECT_DIRECTORY"] = fixtures_path("project_with_binstub")
186-
expect_rspec_to_be_run_as(%w(bin/rspec some args))
187-
@spec_mate.run_rspec(%w(some args))
187+
expect_rspec_to_be_run_as(%w[bin/rspec some args])
188+
@spec_mate.run_rspec(%w[some args])
188189
end
189-
190+
190191
it 'uses `rspec`, if no binstub is present' do
191192
path_to_fake_rspec = File.join(fixtures_path("project_with_binstub"), "bin")
192193
ENV["PATH"] = path_to_fake_rspec + ":" + ENV["PATH"]
193194
ENV["TM_PROJECT_DIRECTORY"] = fixtures_path("legacy_project")
194-
expect_rspec_to_be_run_as(%w(rspec some args))
195-
@spec_mate.run_rspec(%w(some args))
195+
expect_rspec_to_be_run_as(%w[rspec some args])
196+
@spec_mate.run_rspec(%w[some args])
196197
end
197198
end
198-
199+
199200
context 'when TM_RSPEC_BASEDIR is set' do
200201
it 'looks there for the Gemfile.lock' do
201202
ENV["TM_PROJECT_DIRECTORY"] = fixtures_path("project_with_gemfile")
202203
ENV["TM_RSPEC_BASEDIR"] = fixtures_path("project_with_gemfile") + "/subdir"
203-
expect_rspec_to_be_run_as(%w(bundle exec rspec some args))
204-
@spec_mate.run_rspec(%w(some args))
204+
expect_rspec_to_be_run_as(%w[bundle exec rspec some args])
205+
@spec_mate.run_rspec(%w[some args])
205206
end
206207

207208
it 'looks there for the binstub' do
208209
ENV["TM_PROJECT_DIRECTORY"] = fixtures_path("project_with_binstub")
209210
ENV["TM_RSPEC_BASEDIR"] = fixtures_path("project_with_binstub") + "/subdir"
210-
expect_rspec_to_be_run_as(%w(bin/rspec some args))
211-
@spec_mate.run_rspec(%w(some args))
211+
expect_rspec_to_be_run_as(%w[bin/rspec some args])
212+
@spec_mate.run_rspec(%w[some args])
212213
end
213214
end
214-
215215
end
216216

217217
private
218218

219-
def fixtures_path(fixture_file = nil)
219+
def fixtures_path(fixture_file=nil)
220220
# TODO: long path
221221
fixtures_path = File.expand_path(
222222
File.dirname(__FILE__)
@@ -231,5 +231,4 @@ def set_env
231231
ENV['TM_PROJECT_DIRECTORY'] = File.expand_path("../../../../", __FILE__)
232232
ENV['TM_RSPEC_BASEDIR'] = nil
233233
end
234-
235234
end

‎Support/spec/rspec/mate/switch_command_spec.rb

-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def expect_webapp_twins(pair)
4545
it "suggests a plain file" do
4646
expect("/a/full/path/lib/snoopy/mooky.rb").to be_a("file")
4747
end
48-
4948
end
5049

5150
describe "in a Rails or Merb app" do
@@ -166,7 +165,6 @@ def expect_webapp_twins(pair)
166165
it "suggests an rjs view" do
167166
expect("/a/full/path/app/views/mooky/show.js.rjs").to be_a("view")
168167
end
169-
170168
end
171169

172170
describe '#described_class_for' do

‎Support/spec/spec_helper.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
require 'rspec/core/sandbox'
77

88
RSpec.configure do |config|
9-
109
# See https://github.com/rspec/rspec-core/blob/5bee47543e78cf769ee4812c3bf7c00a91765b3a/spec/support/sandboxing.rb
1110
config.around(:example, :sandboxed) do |ex|
12-
RSpec::Core::Sandbox.sandboxed do |config|
11+
RSpec::Core::Sandbox.sandboxed do |sandbox_config|
1312
# If there is an example-within-an-example, we want to make sure the inner example
1413
# does not get a reference to the outer example (the real spec) if it calls
1514
# something like `pending`
16-
config.before(:context) { RSpec.current_example = nil }
15+
sandbox_config.before(:context) { RSpec.current_example = nil }
1716

1817
orig_load_path = $LOAD_PATH.dup
1918
ex.run
+15-18
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11
# This spec file is for manually checking the syntax highlighting. It is not meant to be executed.
22
describe SyntaxHighlighting do
3-
43
it 'works for a simple example (single quoted)' do
54
# ...
65
end
7-
6+
87
it "works for a simple example (double quoted)" do
98
# ...
109
end
11-
10+
1211
context 'in a context (single quoted)' do
1312
context "that is nested (double quoted)" do
1413
it "still works correctly" do
1514
# ...
1615
end
1716
end
1817
end
19-
18+
2019
# See https://github.com/rspec/rspec-tmbundle/issues/45
2120
context 'with multiline
2221
descriptions (single quoted)' do
23-
24-
context "or double
22+
23+
context "or double
2524
quoted" do
26-
27-
it 'still works for
25+
26+
it 'still works for
2827
single quoted strings' do
2928
# ...
3029
end
31-
32-
it "still works for
30+
31+
it "still works for
3332
double quoted strings" do
3433
# ...
3534
end
36-
35+
3736
it 'even works
3837
with pending examples (single quoted)'
3938

@@ -43,18 +42,16 @@
4342
end
4443

4544
context "for pending examples" do
46-
# Make sure `keyword.other.rspec.pending` is really present it may be visually indistinct from `keyword.other.rspec.example`.
45+
# Make sure `keyword.other.rspec.pending` is really present - it may be visually indistinct from `keyword.other.rspec.example`.
4746
it "gives `it` the scope `keyword.other.rspec.pending` (double quotes)"
4847
it 'gives `it` the scope `keyword.other.rspec.pending` (single quotes)'
49-
50-
48+
5149
# In the second line, `context` is not get highlighted correctly if the `meta.rspec.behaviour` scope extends beyond the first line (see https://github.com/rspec/rspec-tmbundle/issues/31)
5250
context "also works for pending contexts"
5351
context "another pending contexts"
54-
5552
end
56-
57-
if foo
53+
54+
if foo # rubocop:disable Style/IfUnlessModifier
5855
puts "Some Ruby code here, #{should} be highlightes correctly", :foo
5956
end
60-
end
57+
end

0 commit comments

Comments
 (0)
Please sign in to comment.