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

Fix options changed after pass it to any notifiers #509

Merged
merged 1 commit into from Oct 23, 2013
Merged

Fix options changed after pass it to any notifiers #509

merged 1 commit into from Oct 23, 2013

Conversation

jinzhu
Copy link
Contributor

@jinzhu jinzhu commented Oct 23, 2013

Hi All,

I got some errors when running tests with guard and guard-gotest, below are those notifiers I am using.

22:38:11 - INFO - Guard is using Libnotify to send notifications.
22:38:11 - INFO - Guard is using Emacs to send notifications.
22:38:11 - INFO - Guard is using TerminalTitle to send notifications.
22:38:11 - INFO - Guard::Gotest is running

My error is Libnotify reported tests failed when got some errors, but emacs got success notification.

When I look into guard, and try to prints the opts at lib/guard/notifier.rb#177 (v2.2.1) and found the opts was changed after finish every notification:

When send the first notification, the opts is {:title=>"Gotest results", :type=>:failed, :priority=>2}
After finish the first notification, the opts changed to {:priority=>2}, (missed the failed type)
After finish the emacs notification, the value became {:priority=>2, :title=>"Guard", :type=>:success, :image=>"/home/jinzhu/.gem/ruby/2.0.0/gems/guard-2.2.1/images/success.png"} (Got some unexpected values)

After doing some research, I found every notifier's notify method inherit Guard::Notifier::Base#notify, but the code of Guard::Notifier::Base#notify looks strange for me:

      def notify(message, opts = {})
        options.delete(:silent)
        ***opts.replace(options.merge(opts))***
        normalize_standard_options!(opts)
      end

It will update the original opts passed to it. I think it should only update the opts for this notifier but not global. So maybe pass a cloned options to each notifier should be a better idea.

Here is a simple code base to explain what's the error, hope it make sense:

def notify opts 
  opts.replace opts.merge(:age => 18)
end

a = {:name => 'testing'}
notify(a)
puts a #=> {:name=>"testing", :age=>18}

b = {:name => 'testing'}
notify(b.dup)
puts b #=> {:name=>"testing"}

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 0b2f761 on jinzhu:fix_options_changed_after_pass_to_notifier into 30d6486 on guard:master.

@rymai
Copy link
Member

rymai commented Oct 23, 2013

Thanks, you're right!

rymai added a commit that referenced this pull request Oct 23, 2013
…_notifier

Fix options changed after pass it to any notifiers
@rymai rymai merged commit 1cfaaa0 into guard:master Oct 23, 2013
@rymai
Copy link
Member

rymai commented Oct 23, 2013

Guard 2.2.2 released, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants