Permalink
Browse files

Don't store evaluated Guardfile in options[: guardfile_contents]

Store it in the instance var guardfile_contents instead.
  • Loading branch information...
1 parent 43fac05 commit 761111ed2ba3d6045656d0d8f6edfffb0052a18d @rymai rymai committed Mar 6, 2014
Showing with 20 additions and 8 deletions.
  1. +5 −4 lib/guard/guardfile/evaluator.rb
  2. +15 −4 spec/lib/guard/guardfile/evaluator_spec.rb
@@ -86,7 +86,7 @@ def guardfile_contents
# @return [String] the Guardfile content
#
def _guardfile_contents_without_user_config
- options[:guardfile_contents] || ''
+ @guardfile_contents || ''
end
# Evaluates the content of the `Guardfile`.
@@ -100,8 +100,7 @@ def _instance_eval_guardfile(contents)
raise ex
end
- # Gets the content to evaluate and stores it into
- # the options as `:guardfile_contents`.
+ # Gets the content to evaluate and stores it into @guardfile_contents.
#
def _fetch_guardfile_contents
_use_inline_guardfile || _use_provided_guardfile || _use_default_guardfile
@@ -115,7 +114,9 @@ def _fetch_guardfile_contents
#
def _use_inline_guardfile
if (@guardfile_source.nil? && options[:guardfile_contents]) || @guardfile_source == :inline
+
@guardfile_source = :inline
+ @guardfile_contents = options[:guardfile_contents]
::Guard::UI.info 'Using inline Guardfile.'
@@ -174,8 +175,8 @@ def _find_default_guardfile
# @param [String] guardfile_path the path to the Guardfile
#
def _read_guardfile(guardfile_path)
- options[:guardfile_contents] = File.read(guardfile_path)
@guardfile_path = guardfile_path
+ @guardfile_contents = File.read(guardfile_path)
rescue => ex
::Guard::UI.error "Error reading file #{ guardfile_path }:"
::Guard::UI.error ex.inspect
@@ -304,11 +304,23 @@ def self.disable_user_config
describe '.reevaluate_guardfile' do
before do
- allow(guardfile_evaluator).to receive(:_instance_eval_guardfile)
allow(::Guard.runner).to receive(:run)
+ guardfile_evaluator.evaluate_guardfile
end
let(:growl) { { name: :growl, options: {} } }
+ context 'with the :guardfile_contents option' do
+ let(:guardfile_evaluator) { described_class.new(guardfile_contents: valid_guardfile_string) }
+
+ it 'skips the reevaluation' do
+ expect(guardfile_evaluator).to_not receive(:_before_reevaluate_guardfile)
+ expect(guardfile_evaluator).to_not receive(:evaluate_guardfile)
+ expect(guardfile_evaluator).to_not receive(:_after_reevaluate_guardfile)
+
+ guardfile_evaluator.reevaluate_guardfile
+ end
+ end
+
describe 'before reevaluation' do
it 'stops all Guards' do
expect(::Guard.runner).to receive(:run).with(:stop)
@@ -374,7 +386,7 @@ def self.disable_user_config
context 'with Guards afterwards' do
before do
- allow(::Guard).to receive(:plugins).and_return([double('Guard::Dummy')])
+ expect(guardfile_evaluator).to receive(:guardfile_contents).exactly(3) { 'guard :rspec' }
allow(::Guard.runner).to receive(:run)
end
@@ -401,11 +413,10 @@ def self.disable_user_config
it 'shows a failure notification' do
expect(::Guard::Notifier).to receive(:notify).with('No plugins found in Guardfile, please add at least one.', title: 'Guard re-evaluate', image: :failed)
- guardfile_evaluator.options[:guardfile_contents] = ''
+ expect(guardfile_evaluator).to receive(:guardfile_contents).exactly(3) { '' }
guardfile_evaluator.reevaluate_guardfile
end
end
-
end
end

0 comments on commit 761111e

Please sign in to comment.