Skip to content

Commit

Permalink
fix all remaining rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed Apr 2, 2016
1 parent 33fd884 commit e907de5
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 61 deletions.
3 changes: 0 additions & 3 deletions .hound.yml
Expand Up @@ -196,9 +196,6 @@ StringLiterals:
VariableInterpolation:
Enabled: false

TrailingComma:
Enabled: false

TrivialAccessors:
Enabled: false

Expand Down
4 changes: 2 additions & 2 deletions lib/guard/rspec/inspectors/focused_inspector.rb
Expand Up @@ -25,8 +25,8 @@ def paths(paths)
def failed(locations)
if locations.empty?
@focused_locations = []
else
@focused_locations = locations if focused_locations.empty?
elsif focused_locations.empty?
@focused_locations = locations
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/options.rb
Expand Up @@ -12,7 +12,7 @@ module Options
launchy: nil,
notification: true,
title: "RSpec results"
}
}.freeze

class << self
def with_defaults(options = {})
Expand Down
2 changes: 0 additions & 2 deletions lib/guard/rspec/rspec_process.rb
Expand Up @@ -56,8 +56,6 @@ def _without_bundler_env
end
end

private

attr_reader :command
attr_reader :exit_code
attr_reader :formatter_tmp_file
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/runner.rb
Expand Up @@ -16,7 +16,7 @@ def initialize
end

# NOTE: must match with const in RSpecFormatter!
TEMPORARY_FILE_PATH ||= "tmp/rspec_guard_result"
TEMPORARY_FILE_PATH ||= "tmp/rspec_guard_result".freeze

attr_accessor :options, :inspector, :notifier

Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/version.rb
@@ -1,5 +1,5 @@
module Guard
module RSpecVersion
VERSION = "4.6.4"
VERSION = "4.6.4".freeze
end
end
2 changes: 1 addition & 1 deletion lib/guard/rspec_defaults.rb
@@ -1,5 +1,5 @@
module Guard
class RSpecDefaults
TEMPORARY_FILE_PATH = "tmp/rspec_guard_result"
TEMPORARY_FILE_PATH = "tmp/rspec_guard_result".freeze
end
end
81 changes: 49 additions & 32 deletions lib/guard/rspec_formatter.rb
Expand Up @@ -12,13 +12,17 @@
module Guard
class RSpecFormatter < ::RSpec::Core::Formatters::BaseFormatter
WIKI_ENV_WARN_URL =
"https://github.com/guard/guard-rspec/wiki/Warning:-no-environment"
"https://github.com/guard/guard-rspec/wiki/Warning:-no-environment".freeze

NO_ENV_WARNING_MSG = "no environment passed - see #{WIKI_ENV_WARN_URL}"
NO_RESULTS_VALUE_MSG = ":results_file value unknown (using defaults)"
NO_ENV_WARNING_MSG =
"no environment passed - see #{WIKI_ENV_WARN_URL}".freeze

UNSUPPORTED_PATTERN = "Your RSpec.configuration.pattern uses characters "\
"unsupported by your Ruby version (File::FNM_EXTGLOB is undefined)"
NO_RESULTS_VALUE_MSG =
":results_file value unknown (using defaults)".freeze

UNSUPPORTED_PATTERN =
"Your RSpec.configuration.pattern uses characters "\
"unsupported by your Ruby version (File::FNM_EXTGLOB is undefined)".freeze

class Error < RuntimeError
class UnsupportedPattern < Error
Expand All @@ -44,41 +48,54 @@ def examples
end
end

# rspec issue https://github.com/rspec/rspec-core/issues/793
def self.extract_spec_location(metadata)
root_metadata = metadata
location = metadata[:location]
class << self
# rspec issue https://github.com/rspec/rspec-core/issues/793
def extract_spec_location(metadata)
root_metadata = metadata
location = metadata[:location]

until spec_path?(location)
metadata = metadata[:parent_example_group] || metadata[:example_group]

until spec_path?(location)
metadata = metadata[:parent_example_group] || metadata[:example_group]
unless metadata
STDERR.puts "no spec file location in #{root_metadata.inspect}"
return root_metadata[:location]
end

unless metadata
STDERR.puts "no spec file location in #{root_metadata.inspect}"
return root_metadata[:location]
# rspec issue https://github.com/rspec/rspec-core/issues/1243
location = first_colon_separated_entry(metadata[:location])
end

# rspec issue https://github.com/rspec/rspec-core/issues/1243
location = (metadata[:location] || "").split(":").first
location
end

location
end
def spec_path?(path)
pattern = ::RSpec.configuration.pattern

flags = supported_fnmatch_flags(pattern)
path ||= ""
path = path.sub(/:\d+\z/, "")
path = Pathname.new(path).cleanpath.to_s
stripped = "{#{pattern.gsub(/\s*,\s*/, ',')}}"
File.fnmatch(stripped, path, flags)
end

def self.spec_path?(path)
pattern = ::RSpec.configuration.pattern
private

flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
if File.const_defined?(:FNM_EXTGLOB) # ruby >= 2
flags |= File::FNM_EXTGLOB
elsif pattern =~ /[{}]/
fail Error::UnsupportedPattern
def first_colon_separated_entry(entries)
(entries || "").split(":").first
end

path ||= ""
path = path.sub(/:\d+\z/, "")
path = Pathname.new(path).cleanpath.to_s
stripped = "{#{pattern.gsub(/\s*,\s*/, ',')}}"
File.fnmatch(stripped, path, flags)
def supported_fnmatch_flags(pattern)
flags = File::FNM_PATHNAME | File::FNM_DOTMATCH

# ruby >= 2
return flags |= File::FNM_EXTGLOB if File.const_defined?(:FNM_EXTGLOB)

fail Error::UnsupportedPattern if pattern =~ /[{}]/

flags
end
end

def dump_summary(*args)
Expand Down Expand Up @@ -135,8 +152,8 @@ def _status_failed?(example)
def _results_file
path = ENV["GUARD_RSPEC_RESULTS_FILE"]
if path.nil?
STDERR.puts "Guard::RSpec: Warning: #{NO_ENV_WARNING_MSG}\n" \
"Guard::RSpec: Warning: #{NO_RESULTS_VALUE_MSG}"
STDERR.puts("Guard::RSpec: Warning: #{NO_ENV_WARNING_MSG}\n" \
"Guard::RSpec: Warning: #{NO_RESULTS_VALUE_MSG}")
path = RSpecDefaults::TEMPORARY_FILE_PATH
end

Expand Down
34 changes: 21 additions & 13 deletions spec/lib/guard/rspec/inspectors/keeping_inspector_spec.rb
Expand Up @@ -58,30 +58,38 @@

# Line numbers in failed_locations needs to be omitted because of
# https://github.com/rspec/rspec-core/issues/952
expect(inspector.paths(other_paths)).to match_array([
"spec/lib/guard/rspec/deprecator_spec.rb",
"spec/lib/guard/rspec/runner_spec.rb",
"spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb"
])
expect(inspector.paths(other_paths)).to match_array(
[
"spec/lib/guard/rspec/deprecator_spec.rb",
"spec/lib/guard/rspec/runner_spec.rb",
"spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb"
]
)
inspector.failed(other_failed_locations)

# Now it returns other failed locations
expect(
inspector.paths(
%w(spec/lib/guard/rspec/inspectors/base_inspector_spec.rb)
)
).to match_array([
"spec/lib/guard/rspec/runner_spec.rb",
"spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb",
"spec/lib/guard/rspec/inspectors/base_inspector_spec.rb"
])
).to match_array(
[
"spec/lib/guard/rspec/runner_spec.rb",
"spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb",
"spec/lib/guard/rspec/inspectors/base_inspector_spec.rb"
]
)
inspector.failed(other_failed_locations)

expect(inspector.paths(%w(spec/lib/guard/rspec/runner_spec.rb))).
to match_array([
expect(
inspector.paths(%w(spec/lib/guard/rspec/runner_spec.rb))
).to match_array(
[
"spec/lib/guard/rspec/runner_spec.rb",
"spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb"
])
]
)

inspector.failed([])

# Now there is no failed locations
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/guard/rspec/results_spec.rb
Expand Up @@ -16,7 +16,7 @@
[
"5 examples, 2 failures (3 pending)\n",
"foo1/bar1_spec.rb\n",
"foo1/bar2_spec.rb\n",
"foo1/bar2_spec.rb\n"
]
end

Expand Down
10 changes: 6 additions & 4 deletions spec/lib/guard/rspec/runner_spec.rb
Expand Up @@ -272,10 +272,12 @@

context "with failed paths" do
before do
allow(results).to receive(:failed_paths).and_return([
"./failed_spec.rb:123",
"./other/failed_spec.rb:77"
])
allow(results).to receive(:failed_paths).and_return(
[
"./failed_spec.rb:123",
"./other/failed_spec.rb:77"
]
)
end

it "notifies inspector about failed paths" do
Expand Down

0 comments on commit e907de5

Please sign in to comment.