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

Handle ':group' and ':plugin' in scope (Guardfile) #706

Merged
merged 3 commits into from Dec 22, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/Guardfile
@@ -1,3 +1,5 @@
scope(groups: %w(specs))

directories %w(spec lib config features man)

watch ("config/Guardfile") { UI.info "Exiting guard because config changed"; exit 0 }
Expand Down
11 changes: 9 additions & 2 deletions lib/guard/internals/session.rb
Expand Up @@ -72,8 +72,15 @@ def initialize(new_options)

def guardfile_scope(scope)
opts = scope.dup
@guardfile_plugin_scope = Array(opts.delete(:plugins))
@guardfile_group_scope = Array(opts.delete(:groups))

groups = Array(opts.delete(:groups))
group = Array(opts.delete(:group))
@guardfile_group_scope = Array(groups) + Array(group)

plugins = Array(opts.delete(:plugins))
plugin = Array(opts.delete(:plugin))
@guardfile_plugin_scope = Array(plugins) + Array(plugin)

fail "Unknown options: #{opts.inspect}" unless opts.empty?
end

Expand Down
16 changes: 5 additions & 11 deletions lib/guard/templates/Guardfile
Expand Up @@ -7,13 +7,12 @@
## Uncomment to clear the screen before every task
# clearing :on

## Make Guard exit when config is changed so it can be restarted
#
## Note: if you want Guard to automatically start up again, run guard in a
## Guard internally checks for changes in the Guardfile and exits.
## If you want Guard to automatically start up again, run guard in a
## shell loop, e.g.:
#
# $ while bundle exec guard; do echo "Restarting Guard..."; done
#
##
## $ while bundle exec guard; do echo "Restarting Guard..."; done
##
## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), the you will want to move the Guardfile
## to a watched dir and symlink it back, e.g.
Expand All @@ -23,8 +22,3 @@
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
#
watch ("Guardfile") do
UI.info "Exiting because Guard must be restarted for changes to take effect"
exit 0
end
35 changes: 35 additions & 0 deletions spec/lib/guard/internals/session_spec.rb
Expand Up @@ -147,6 +147,41 @@
end
end

describe "#guardfile_scope" do
before do
subject.guardfile_scope(scope)
end

context "with a groups scope" do
let(:scope) { { groups: [:foo] } }
it "sets the groups" do
expect(subject.guardfile_group_scope).to eq([:foo])
end
end

context "with a group scope" do
let(:scope) { { group: [:foo] } }
it "sets the groups" do
expect(subject.guardfile_group_scope).to eq([:foo])
end
end

context "with a plugin scope" do
let(:scope) { { plugin: [:foo] } }
it "sets the plugins" do
expect(subject.guardfile_plugin_scope).to eq([:foo])
end
end

context "with a plugins scope" do
let(:scope) { { plugins: [:foo] } }
it "sets the plugins" do
expect(subject.guardfile_plugin_scope).to eq([:foo])
end
end

end

describe ".convert_scope" do
let(:foo) { instance_double("Guard::Plugin", name: "foo") }
let(:bar) { instance_double("Guard::Plugin", name: "bar") }
Expand Down