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

[RFC] Change Guard::RSpec to be a module and create Plugin which includes Compat::API #397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
filename = "gemfiles/common"
instance_eval(IO.read(filename), filename, 1)

gem 'guard', github: 'guard/guard', branch: 'guard-api'

group :test do
gem "rspec", "~> 3.4"
end
Expand All @@ -21,5 +23,6 @@ end
group :development do
gem "rubocop", require: false
gem "guard-rubocop", require: false
gem "guard-compat", ">= 0.0.2", require: false
# gem "guard-compat", ">= 0.0.2", require: false
gem 'guard-compat', github: 'guard/guard-compat', branch: 'guard-api', require: false
end
2 changes: 1 addition & 1 deletion guard-rspec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require "guard/rspec/version"

Gem::Specification.new do |s|
s.name = "guard-rspec"
s.version = Guard::RSpecVersion::VERSION
s.version = Guard::RSpec::VERSION
s.author = "Thibaud Guillaume-Gentil"
s.email = "thibaud@thibaud.gg"
s.summary = "Guard gem for RSpec"
Expand Down
43 changes: 1 addition & 42 deletions lib/guard/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,7 @@
require "guard/rspec/deprecator"
require "guard/rspec/runner"

# NOTE: To avoid 'superclass mismatch for class RSpec' errors,
# every file has to have
#
# class RSpec < Plugin
#
# and not just
#
# class RSpec

module Guard
class RSpec < Plugin
attr_accessor :options, :runner

def initialize(options = {})
super
@options = Options.with_defaults(options)
Deprecator.warns_about_deprecated_options(@options)
@runner = Runner.new(@options)
end

def start
Compat::UI.info "Guard::RSpec is running"
run_all if options[:all_on_start]
end

def run_all
_throw_if_failed { runner.run_all }
end

def reload
runner.reload
end

def run_on_modifications(paths)
return false if paths.empty?
_throw_if_failed { runner.run(paths) }
end

private

def _throw_if_failed
throw :task_has_failed unless yield
end
module RSpec
end
end
2 changes: 1 addition & 1 deletion lib/guard/rspec/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "guard/rspec"

module Guard
class RSpec < Plugin
module RSpec
class Command < String
FAILURE_EXIT_CODE = 2

Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/deprecator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Guard
class RSpec < Plugin
module RSpec
class Deprecator
attr_accessor :options

Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "guard/rspec"

module Guard
class RSpec < Plugin
module RSpec
class Dsl
def initialize(dsl)
@dsl = dsl
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/inspectors/base_inspector.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Guard
class RSpec < Plugin
module RSpec
module Inspectors
class BaseInspector
attr_accessor :options, :spec_paths
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/inspectors/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "guard/rspec/inspectors/focused_inspector.rb"

module Guard
class RSpec < Plugin
module RSpec
module Inspectors
class Factory
class << self
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/inspectors/focused_inspector.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "guard/rspec/inspectors/base_inspector.rb"

module Guard
class RSpec < Plugin
module RSpec
module Inspectors
# Inspector that focuses on set of paths if any of them is failing.
# Returns only that set of paths on all future calls to #paths
Expand Down
4 changes: 2 additions & 2 deletions lib/guard/rspec/inspectors/keeping_inspector.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "guard/rspec/inspectors/base_inspector.rb"

module Guard
class RSpec < Plugin
module RSpec
module Inspectors
# Inspector that remembers all failed paths and
# returns that paths in future calls to #paths method
Expand Down Expand Up @@ -52,7 +52,7 @@ def _location_path(location)
# https://github.com/rspec/rspec-core/issues/952
#
# module Guard
# class RSpec < Plugin
# module RSpec
# module Inspectors
# # Inspector that remembers all failed paths and
# # returns that paths in future calls to #paths method
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/inspectors/simple_inspector.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "guard/rspec/inspectors/base_inspector"

module Guard
class RSpec < Plugin
module RSpec
module Inspectors
class SimpleInspector < BaseInspector
def paths(paths)
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/notifier.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Guard
class RSpec < Plugin
module RSpec
class Notifier
attr_accessor :options

Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/options.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Guard
class RSpec < Plugin
module RSpec
module Options
DEFAULTS = {
all_on_start: false,
Expand Down
40 changes: 40 additions & 0 deletions lib/guard/rspec/plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Guard

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.

module RSpec
class Plugin
include Compat::API

attr_accessor :runner

def initialize(opts = {})
super
@options = Options.with_defaults(opts)
Deprecator.warns_about_deprecated_options(options)
@runner = Runner.new(options)
end

def start
Compat::UI.info "Guard::RSpec is running"
run_all if options[:all_on_start]
end

def run_all
_throw_if_failed { runner.run_all }
end

def reload
runner.reload
end

def run_on_modifications(paths)
return false if paths.empty?
_throw_if_failed { runner.run(paths) }
end

private

def _throw_if_failed
throw :task_has_failed unless yield
end
end
end
end
2 changes: 1 addition & 1 deletion lib/guard/rspec/results.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Guard
class RSpec < Plugin
module RSpec
class Results
class InvalidData < RuntimeError
end
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/rspec_process.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "guard/rspec/command"

module Guard
class RSpec < Plugin
module RSpec
class RSpecProcess
class Failure < RuntimeError
end
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 @@ -7,7 +7,7 @@
require "guard/rspec/rspec_process"

module Guard
class RSpec < Plugin
module RSpec
class Runner
class NoCmdOptionError < RuntimeError
def initialize
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
module RSpec
VERSION = "4.7.3".freeze
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require "guard/compat/test/helper"
require "guard/rspec"
require "guard/rspec/plugin"

RSpec.describe Guard::RSpec do
RSpec.describe Guard::RSpec::Plugin do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block has too many lines. [72/25]

let(:default_options) { Guard::RSpec::Options::DEFAULTS }
let(:options) { {} }
let(:plugin) { Guard::RSpec.new(options) }
let(:plugin) { described_class.new(options) }
let(:runner) { instance_double(Guard::RSpec::Runner) }

before do
Expand All @@ -14,23 +14,25 @@
end

describe ".initialize" do
let(:options) { { foo: :bar } }

it "instanciates with default and custom options" do
guard_rspec = Guard::RSpec.new(foo: :bar)
expect(guard_rspec.options).to eq(default_options.merge(foo: :bar))
expect(plugin.options).to eq(default_options.merge(options))
end

it "instanciates Runner with all default and custom options" do
expect(Guard::RSpec::Runner).to receive(:new).
with(default_options.merge(foo: :bar))
Guard::RSpec.new(foo: :bar)
with(default_options.merge(options))

plugin
end

it "warns deprecated options" do
expect(Guard::RSpec::Deprecator).
to receive(:warns_about_deprecated_options).
with(default_options.merge(foo: :bar))
with(default_options.merge(options))

Guard::RSpec.new(foo: :bar)
plugin
end
end

Expand Down