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

Use Guard::Compat + update to RSpec 3.1 #19

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
5 changes: 4 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

RSpec::Core::RakeTask.new(:spec)
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = (ENV['CI'] == 'true')
end

RuboCop::RakeTask.new(:style)

namespace :ci do
Expand Down
3 changes: 2 additions & 1 deletion guard-rubocop.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_runtime_dependency 'guard', '~> 2.0'
spec.add_runtime_dependency 'guard-compat', '~> 1.1'
spec.add_runtime_dependency 'rubocop', '~> 0.20'

spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rspec', '~> 3.1'
spec.add_development_dependency 'simplecov', '~> 0.7'
spec.add_development_dependency 'guard-rspec', '>= 4.2.3', '< 5.0'
spec.add_development_dependency 'ruby_gntp', '~> 0.3'
Expand Down
13 changes: 7 additions & 6 deletions lib/guard/rubocop.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# coding: utf-8

require 'guard'
require 'guard/plugin'
require 'tempfile'

require 'guard/compat/plugin'

module Guard
# This class gets API calls from `guard` and runs `rubocop` command via {Guard::RuboCop::Runner}.
Expand Down Expand Up @@ -30,7 +31,7 @@ def start
end

def run_all
UI.info 'Inspecting Ruby code style of all files'
Compat::UI.info 'Inspecting Ruby code style of all files'
inspect_with_rubocop
end

Expand All @@ -55,7 +56,7 @@ def run_partially(paths)
return if paths.empty?

displayed_paths = paths.map { |path| smart_path(path) }
UI.info "Inspecting Ruby code style: #{displayed_paths.join(' ')}"
Compat::UI.info "Inspecting Ruby code style: #{displayed_paths.join(' ')}"

inspect_with_rubocop(paths)
end
Expand All @@ -65,8 +66,8 @@ def inspect_with_rubocop(paths = [])
passed = runner.run(paths)
@failed_paths = runner.failed_paths
throw :task_has_failed unless passed
rescue => error
UI.error 'The following exception occurred while running guard-rubocop: ' \
rescue StandardError => error
Compat::UI.error 'The following exception occurred while running guard-rubocop: ' \
"#{error.backtrace.first} #{error.message} (#{error.class.name})"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rubocop/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def result

def notify(passed)
image = passed ? :success : :failed
Notifier.notify(summary_text, title: 'RuboCop results', image: image)
Compat::UI.notify(summary_text, title: 'RuboCop results', image: image)
end

def summary_text
Expand Down
14 changes: 8 additions & 6 deletions spec/guard/rubocop/runner_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# coding: utf-8

require 'spec_helper.rb'
require 'guard/compat/test/helper'

describe Guard::RuboCop::Runner do
require 'guard/rubocop'

RSpec.describe Guard::RuboCop::Runner do
subject(:runner) { Guard::RuboCop::Runner.new(options) }
let(:options) { {} }

Expand Down Expand Up @@ -345,22 +347,22 @@
end

it 'notifies summary' do
expect(Guard::Notifier).to receive(:notify) do |message, _options|
expect(Guard::Compat::UI).to receive(:notify) do |message, _options|
expect(message).to eq('2 files inspected, 4 offenses detected')
end
runner.notify(true)
end

it 'notifies with title "RuboCop results"' do
expect(Guard::Notifier).to receive(:notify) do |_message, options|
expect(Guard::Compat::UI).to receive(:notify) do |_message, options|
expect(options[:title]).to eq('RuboCop results')
end
runner.notify(true)
end

context 'when passed' do
it 'shows success image' do
expect(Guard::Notifier).to receive(:notify) do |_message, options|
expect(Guard::Compat::UI).to receive(:notify) do |_message, options|
expect(options[:image]).to eq(:success)
end
runner.notify(true)
Expand All @@ -369,7 +371,7 @@

context 'when failed' do
it 'shows failed image' do
expect(Guard::Notifier).to receive(:notify) do |_message, options|
expect(Guard::Compat::UI).to receive(:notify) do |_message, options|
expect(options[:image]).to eq(:failed)
end
runner.notify(false)
Expand Down
18 changes: 18 additions & 0 deletions spec/guard/rubocop/template_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'guard/compat/test/template'

require 'guard/rubocop'

RSpec.describe Guard::RuboCop do
describe 'template' do
subject { Guard::Compat::Test::Template.new(described_class) }

it 'matches Ruby files' do
expect(subject.changed('lib/foo.rb')).to eq(%w(lib/foo.rb))
end

it 'matches .rubocop.yml files' do
expect(subject.changed('.rubocop.yml')).to eq(%w(.))
expect(subject.changed('foo/.rubocop.yml')).to eq(%w(foo))
end
end
end
9 changes: 6 additions & 3 deletions spec/guard/rubocop_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# coding: utf-8

require 'spec_helper.rb'

describe Guard::RuboCop, :silence_output do
RSpec.describe Guard::RuboCop, :silence_output do
subject(:guard) { Guard::RuboCop.new(options) }
let(:options) { {} }

before do
allow(Guard::Compat::UI).to receive(:info)
allow(Guard::Compat::UI).to receive(:error)
end

describe '#options' do
subject { super().options }

Expand Down
27 changes: 19 additions & 8 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
# coding: utf-8

RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

config.mock_with :rspec do |c|
c.syntax = :expect
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end

config.filter_run :focus
config.run_all_when_everything_filtered = true

config.disable_monkey_patching!

config.warnings = true

config.default_formatter = 'doc' if config.files_to_run.one?

# config.profile_examples = 10

config.order = :random

Kernel.srand config.seed
end

Dir[File.join(File.dirname(__FILE__), 'support', '*')].each do |path|
Expand All @@ -29,5 +42,3 @@
add_filter '/spec/'
add_filter '/vendor/bundle/'
end

require 'guard/rubocop'
2 changes: 1 addition & 1 deletion spec/support/silence_output.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8

shared_context 'silence output', silence_output: true do
RSpec.shared_context 'silence output', silence_output: true do
null_object = BasicObject.new

class << null_object
Expand Down