forked from supaspoida/guard-focus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24b054f
commit 8101779
Showing
7 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'guard' | ||
require 'guard/guard' | ||
require 'forwardable' | ||
|
||
module Guard | ||
class Focus < Guard | ||
autoload :Libraries, 'guard/focus/libraries' | ||
|
||
extend Forwardable | ||
|
||
def_delegators :library, :base_path, :executable, :extension, :focus_regexp | ||
|
||
attr_reader :paths, :focused, :library | ||
|
||
def initialize(watchers=[], options={}) | ||
super | ||
@library = Libraries[options[:on]] | ||
end | ||
|
||
def run_all | ||
success?([base_path]) | ||
end | ||
|
||
def run_on_change(files) | ||
success?(files) | ||
end | ||
|
||
private | ||
|
||
def command | ||
['time', executable, paths.join(' '), options].compact * ' ' | ||
end | ||
|
||
def has_focus?(file) | ||
begin | ||
File.read(file) =~ focus_regexp | ||
rescue Errno::EISDIR => e | ||
Dir.glob("#{file}/**/*#{extension}").any? &method(:has_focus?) | ||
rescue Errno::ENOENT => e | ||
UI.debug "\e[31mMissing directory: #{base_path}" | ||
end | ||
end | ||
|
||
def options | ||
'--tag @focus' if focused | ||
end | ||
|
||
def success?(paths) | ||
@paths = paths | ||
@focused = paths.any? &method(:has_focus?) | ||
UI.info "\nRunning: \e[33m#{command}\n" | ||
system command | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'ostruct' | ||
|
||
module Guard | ||
class Focus | ||
class Libraries < OpenStruct | ||
def self.cucumber | ||
new base_path: 'features', | ||
focus_regexp: /^\s*@focus/, | ||
executable: 'cucumber', | ||
extension: '.feature' | ||
end | ||
|
||
def self.rspec | ||
new base_path: 'spec', | ||
focus_regexp: /^\s*(describe|context|it).*?(:focus|focus:)/, | ||
executable: 'rspec', | ||
extension: '_spec.rb' | ||
end | ||
|
||
def self.[](name) | ||
{ cucumber: cucumber, | ||
rspec: rspec }[name] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
guard 'focus', on: :rspec do | ||
watch(%r{^spec/.+_spec\.rb}) | ||
watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" } | ||
watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" } | ||
watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" } | ||
end | ||
|
||
guard 'focus', on: :cucumber do | ||
watch(%r{^features/.+\.feature$}) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Guard | ||
module Focus | ||
module FocusVersion | ||
VERSION = "0.0.1" | ||
end | ||
end |