Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix all remaining rubocop offenses #364

Merged
merged 1 commit into from
Apr 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .hound.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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