uniform_notifier 1.11.0 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +17 -1
  4. data/Gemfile +3 -1
  5. data/README.md +95 -77
  6. data/Rakefile +13 -11
  7. data/lib/uniform_notifier.rb +37 -10
  8. data/lib/uniform_notifier/airbrake.rb +3 -3
  9. data/lib/uniform_notifier/base.rb +17 -14
  10. data/lib/uniform_notifier/bugsnag.rb +4 -7
  11. data/lib/uniform_notifier/customized_logger.rb +6 -4
  12. data/lib/uniform_notifier/errors.rb +3 -1
  13. data/lib/uniform_notifier/growl.rb +20 -21
  14. data/lib/uniform_notifier/honeybadger.rb +5 -4
  15. data/lib/uniform_notifier/javascript_alert.rb +7 -3
  16. data/lib/uniform_notifier/javascript_console.rb +18 -14
  17. data/lib/uniform_notifier/rails_logger.rb +3 -1
  18. data/lib/uniform_notifier/raise.rb +4 -2
  19. data/lib/uniform_notifier/rollbar.rb +8 -1
  20. data/lib/uniform_notifier/sentry.rb +3 -3
  21. data/lib/uniform_notifier/slack.rb +20 -22
  22. data/lib/uniform_notifier/terminal_notifier.rb +24 -0
  23. data/lib/uniform_notifier/version.rb +3 -1
  24. data/lib/uniform_notifier/xmpp.rb +25 -24
  25. data/spec/spec_helper.rb +8 -6
  26. data/spec/uniform_notifier/airbrake_spec.rb +12 -10
  27. data/spec/uniform_notifier/base_spec.rb +12 -14
  28. data/spec/uniform_notifier/bugsnag_spec.rb +33 -19
  29. data/spec/uniform_notifier/customized_logger_spec.rb +9 -7
  30. data/spec/uniform_notifier/growl_spec.rb +41 -23
  31. data/spec/uniform_notifier/honeybadger_spec.rb +12 -10
  32. data/spec/uniform_notifier/javascript_alert_spec.rb +29 -9
  33. data/spec/uniform_notifier/javascript_console_spec.rb +55 -17
  34. data/spec/uniform_notifier/rails_logger_spec.rb +9 -7
  35. data/spec/uniform_notifier/raise_spec.rb +15 -16
  36. data/spec/uniform_notifier/rollbar_spec.rb +15 -6
  37. data/spec/uniform_notifier/sentry_spec.rb +12 -10
  38. data/spec/uniform_notifier/slack_spec.rb +12 -8
  39. data/spec/uniform_notifier/terminal_notifier_spec.rb +27 -0
  40. data/spec/uniform_notifier/xmpp_spec.rb +21 -15
  41. data/uniform_notifier.gemspec +24 -17
  42. metadata +30 -25
@@ -1,7 +1,9 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
1
+ # frozen_string_literal: true
2
2
 
3
- require "uniform_notifier"
4
- require "ruby-growl"
5
- require "xmpp4r"
6
- require "slack-notifier"
7
- require "rspec"
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'uniform_notifier'
6
+ require 'ruby-growl'
7
+ require 'xmpp4r'
8
+ require 'slack-notifier'
9
+ require 'rspec'
@@ -1,25 +1,27 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  class Airbrake
4
6
  # mock Airbrake
5
7
  end
6
8
 
7
9
  RSpec.describe UniformNotifier::AirbrakeNotifier do
8
- it "should not notify airbrake" do
9
- expect(UniformNotifier::AirbrakeNotifier.out_of_channel_notify(:title => "notify airbrake")).to be_nil
10
+ it 'should not notify airbrake' do
11
+ expect(UniformNotifier::AirbrakeNotifier.out_of_channel_notify(title: 'notify airbrake')).to be_nil
10
12
  end
11
13
 
12
- it "should notify airbrake" do
13
- expect(Airbrake).to receive(:notify).with(UniformNotifier::Exception.new("notify airbrake"), {})
14
+ it 'should notify airbrake' do
15
+ expect(Airbrake).to receive(:notify).with(UniformNotifier::Exception.new('notify airbrake'), {})
14
16
 
15
17
  UniformNotifier.airbrake = true
16
- UniformNotifier::AirbrakeNotifier.out_of_channel_notify(:title => "notify airbrake")
18
+ UniformNotifier::AirbrakeNotifier.out_of_channel_notify(title: 'notify airbrake')
17
19
  end
18
20
 
19
- it "should notify airbrake" do
20
- expect(Airbrake).to receive(:notify).with(UniformNotifier::Exception.new("notify airbrake"), :foo => :bar)
21
+ it 'should notify airbrake' do
22
+ expect(Airbrake).to receive(:notify).with(UniformNotifier::Exception.new('notify airbrake'), foo: :bar)
21
23
 
22
- UniformNotifier.airbrake = { :foo => :bar }
23
- UniformNotifier::AirbrakeNotifier.out_of_channel_notify("notify airbrake")
24
+ UniformNotifier.airbrake = { foo: :bar }
25
+ UniformNotifier::AirbrakeNotifier.out_of_channel_notify('notify airbrake')
24
26
  end
25
27
  end
@@ -1,22 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe UniformNotifier::Base do
4
- context "#inline_channel_notify" do
5
- before do
6
- allow(UniformNotifier::Base).to receive(:active?).and_return(true)
7
- end
8
- it "should keep the compatibility" do
9
- expect(UniformNotifier::Base).to receive(:_inline_notify).once.with(:title => "something")
10
- UniformNotifier::Base.inline_notify("something")
6
+ context '#inline_channel_notify' do
7
+ before { allow(UniformNotifier::Base).to receive(:active?).and_return(true) }
8
+ it 'should keep the compatibility' do
9
+ expect(UniformNotifier::Base).to receive(:_inline_notify).once.with(title: 'something')
10
+ UniformNotifier::Base.inline_notify('something')
11
11
  end
12
12
  end
13
- context "#out_of_channel_notify" do
14
- before do
15
- allow(UniformNotifier::Base).to receive(:active?).and_return(true)
16
- end
17
- it "should keep the compatibility" do
18
- expect(UniformNotifier::Base).to receive(:_out_of_channel_notify).once.with(:title => "something")
19
- UniformNotifier::Base.out_of_channel_notify("something")
13
+ context '#out_of_channel_notify' do
14
+ before { allow(UniformNotifier::Base).to receive(:active?).and_return(true) }
15
+ it 'should keep the compatibility' do
16
+ expect(UniformNotifier::Base).to receive(:_out_of_channel_notify).once.with(title: 'something')
17
+ UniformNotifier::Base.out_of_channel_notify('something')
20
18
  end
21
19
  end
22
20
  end
@@ -1,4 +1,6 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  class Bugsnag
4
6
  # mock Bugsnag
@@ -6,51 +8,63 @@ end
6
8
 
7
9
  RSpec.describe UniformNotifier::BugsnagNotifier do
8
10
  let(:notification_data) { {} }
9
- it "should not notify bugsnag" do
11
+ it 'should not notify bugsnag' do
10
12
  expect(Bugsnag).not_to receive(:notify)
11
13
  UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data)
12
14
  end
13
- context "with string notification" do
14
- let(:notification_data) { {:user => 'user', :title => 'notify bugsnag', :url => 'URL', body: 'something'} }
15
+ context 'with string notification' do
16
+ let(:notification_data) { { user: 'user', title: 'notify bugsnag', url: 'URL', body: 'something' } }
15
17
 
16
- it "should notify bugsnag" do
17
- expect(Bugsnag).to receive(:notify).with(UniformNotifier::Exception.new(notification_data[:title]), :grouping_hash => notification_data[:body], :notification => notification_data)
18
+ it 'should notify bugsnag' do
19
+ expect(Bugsnag).to receive(:notify).with(
20
+ UniformNotifier::Exception.new(notification_data[:title]),
21
+ grouping_hash: notification_data[:body], notification: notification_data
22
+ )
18
23
 
19
24
  UniformNotifier.bugsnag = true
20
25
  UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data)
21
26
  end
22
27
 
23
- it "should notify bugsnag with option" do
24
- expect(Bugsnag).to receive(:notify).with(UniformNotifier::Exception.new(notification_data[:title]), :foo => :bar, :grouping_hash => notification_data[:body], :notification => notification_data)
28
+ it 'should notify bugsnag with option' do
29
+ expect(Bugsnag).to receive(:notify).with(
30
+ UniformNotifier::Exception.new(notification_data[:title]),
31
+ foo: :bar, grouping_hash: notification_data[:body], notification: notification_data
32
+ )
25
33
 
26
- UniformNotifier.bugsnag = { :foo => :bar }
34
+ UniformNotifier.bugsnag = { foo: :bar }
27
35
  UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data)
28
36
  end
29
37
  end
30
- context "with hash notification" do
31
- let(:notification_data) { "notify bugsnag" }
38
+ context 'with hash notification' do
39
+ let(:notification_data) { 'notify bugsnag' }
32
40
 
33
- it "should notify bugsnag" do
34
- expect(Bugsnag).to receive(:notify).with(UniformNotifier::Exception.new("notify bugsnag"), :grouping_hash => "notify bugsnag", :notification => {:title => "notify bugsnag"})
41
+ it 'should notify bugsnag' do
42
+ expect(Bugsnag).to receive(:notify).with(
43
+ UniformNotifier::Exception.new('notify bugsnag'),
44
+ grouping_hash: 'notify bugsnag', notification: { title: 'notify bugsnag' }
45
+ )
35
46
 
36
47
  UniformNotifier.bugsnag = true
37
48
  UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data)
38
49
  end
39
50
 
40
- it "should notify bugsnag with option" do
41
- expect(Bugsnag).to receive(:notify).with(UniformNotifier::Exception.new("notify bugsnag"), :foo => :bar, :grouping_hash => "notify bugsnag", :notification => {:title => "notify bugsnag"})
51
+ it 'should notify bugsnag with option' do
52
+ expect(Bugsnag).to receive(:notify).with(
53
+ UniformNotifier::Exception.new('notify bugsnag'),
54
+ foo: :bar, grouping_hash: 'notify bugsnag', notification: { title: 'notify bugsnag' }
55
+ )
42
56
 
43
- UniformNotifier.bugsnag = { :foo => :bar }
57
+ UniformNotifier.bugsnag = { foo: :bar }
44
58
  UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data)
45
59
  end
46
60
  end
47
61
 
48
- it "should notify bugsnag with correct backtrace" do
62
+ it 'should notify bugsnag with correct backtrace' do
49
63
  expect(Bugsnag).to receive(:notify) do |error|
50
64
  expect(error).to be_a UniformNotifier::Exception
51
- expect(error.backtrace).to eq ["bugsnag spec test"]
65
+ expect(error.backtrace).to eq ['bugsnag spec test']
52
66
  end
53
67
  UniformNotifier.bugsnag = true
54
- UniformNotifier::BugsnagNotifier.out_of_channel_notify(backtrace: ["bugsnag spec test"])
68
+ UniformNotifier::BugsnagNotifier.out_of_channel_notify(backtrace: ['bugsnag spec test'])
55
69
  end
56
70
  end
@@ -1,21 +1,23 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  RSpec.describe UniformNotifier::CustomizedLogger do
4
- it "should not notify to customized logger" do
5
- expect(UniformNotifier::CustomizedLogger.out_of_channel_notify(:title => "notify rails logger")).to be_nil
6
+ it 'should not notify to customized logger' do
7
+ expect(UniformNotifier::CustomizedLogger.out_of_channel_notify(title: 'notify rails logger')).to be_nil
6
8
  end
7
9
 
8
- it "should notify to customized logger" do
9
- logger = File.open( 'test.log', 'a+' )
10
+ it 'should notify to customized logger' do
11
+ logger = File.open('test.log', 'a+')
10
12
  logger.sync = true
11
13
 
12
14
  now = Time.now
13
15
  allow(Time).to receive(:now).and_return(now)
14
16
  UniformNotifier.customized_logger = logger
15
- UniformNotifier::CustomizedLogger.out_of_channel_notify(:title => "notify rails logger")
17
+ UniformNotifier::CustomizedLogger.out_of_channel_notify(title: 'notify rails logger')
16
18
 
17
19
  logger.seek(0)
18
- expect(logger.read).to eq "#{now.strftime("%Y-%m-%d %H:%M:%S")}[WARN] notify rails logger"
20
+ expect(logger.read).to eq "#{now.strftime('%Y-%m-%d %H:%M:%S')}[WARN] notify rails logger"
19
21
 
20
22
  File.delete('test.log')
21
23
  end
@@ -1,56 +1,74 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe UniformNotifier::Growl do
4
-
5
- it "should not notify growl" do
6
- expect(UniformNotifier::Growl.out_of_channel_notify(:title => 'notify growl')).to be_nil
6
+ it 'should not notify growl' do
7
+ expect(UniformNotifier::Growl.out_of_channel_notify(title: 'notify growl')).to be_nil
7
8
  end
8
9
 
9
- it "should notify growl without password" do
10
- growl = double('growl', :is_a? => true)
10
+ it 'should notify growl without password' do
11
+ growl = double('growl', is_a?: true)
11
12
  expect(Growl).to receive(:new).with('localhost', 'uniform_notifier').and_return(growl)
12
13
  expect(growl).to receive(:add_notification).with('uniform_notifier')
13
14
  expect(growl).to receive(:password=).with(nil)
14
- expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on').ordered
15
- expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl without password').ordered
15
+ expect(growl).to receive(:notify).with(
16
+ 'uniform_notifier',
17
+ 'Uniform Notifier',
18
+ 'Uniform Notifier Growl has been turned on'
19
+ ).ordered
20
+ expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl without password')
21
+ .ordered
16
22
 
17
23
  UniformNotifier.growl = true
18
- UniformNotifier::Growl.out_of_channel_notify(:title => 'notify growl without password')
24
+ UniformNotifier::Growl.out_of_channel_notify(title: 'notify growl without password')
19
25
  end
20
26
 
21
- it "should notify growl with password" do
22
- growl = double('growl', :is_a? => true)
27
+ it 'should notify growl with password' do
28
+ growl = double('growl', is_a?: true)
23
29
  expect(Growl).to receive(:new).with('localhost', 'uniform_notifier').and_return(growl)
24
30
  expect(growl).to receive(:add_notification).with('uniform_notifier')
25
31
  expect(growl).to receive(:password=).with('123456')
26
- expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on').ordered
32
+ expect(growl).to receive(:notify).with(
33
+ 'uniform_notifier',
34
+ 'Uniform Notifier',
35
+ 'Uniform Notifier Growl has been turned on'
36
+ ).ordered
27
37
  expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl with password').ordered
28
38
 
29
- UniformNotifier.growl = { :password => '123456' }
30
- UniformNotifier::Growl.out_of_channel_notify(:title => 'notify growl with password')
39
+ UniformNotifier.growl = { password: '123456' }
40
+ UniformNotifier::Growl.out_of_channel_notify(title: 'notify growl with password')
31
41
  end
32
42
 
33
- it "should notify growl with host" do
34
- growl = double('growl', :is_a? => true)
43
+ it 'should notify growl with host' do
44
+ growl = double('growl', is_a?: true)
35
45
  expect(Growl).to receive(:new).with('10.10.156.17', 'uniform_notifier').and_return(growl)
36
46
  expect(growl).to receive(:add_notification).with('uniform_notifier')
37
47
  expect(growl).to receive(:password=).with('123456')
38
- expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on').ordered
48
+ expect(growl).to receive(:notify).with(
49
+ 'uniform_notifier',
50
+ 'Uniform Notifier',
51
+ 'Uniform Notifier Growl has been turned on'
52
+ ).ordered
39
53
  expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl with password').ordered
40
54
 
41
- UniformNotifier.growl = { :password => '123456', :host => '10.10.156.17' }
42
- UniformNotifier::Growl.out_of_channel_notify(:title => 'notify growl with password')
55
+ UniformNotifier.growl = { password: '123456', host: '10.10.156.17' }
56
+ UniformNotifier::Growl.out_of_channel_notify(title: 'notify growl with password')
43
57
  end
44
58
 
45
- it "should notify growl with quiet" do
46
- growl = double('growl', :is_a? => true)
59
+ it 'should notify growl with quiet' do
60
+ growl = double('growl', is_a?: true)
47
61
  expect(Growl).to receive(:new).with('localhost', 'uniform_notifier').and_return(growl)
48
62
  expect(growl).to receive(:add_notification).with('uniform_notifier')
49
63
  expect(growl).to receive(:password=).with('123456')
50
- expect(growl).not_to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on')
64
+ expect(growl).not_to receive(:notify).with(
65
+ 'uniform_notifier',
66
+ 'Uniform Notifier',
67
+ 'Uniform Notifier Growl has been turned on'
68
+ )
51
69
  expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl with password')
52
70
 
53
- UniformNotifier.growl = { :password => '123456', :quiet => true }
54
- UniformNotifier::Growl.out_of_channel_notify(:title => 'notify growl with password')
71
+ UniformNotifier.growl = { password: '123456', quiet: true }
72
+ UniformNotifier::Growl.out_of_channel_notify(title: 'notify growl with password')
55
73
  end
56
74
  end
@@ -1,25 +1,27 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  class Honeybadger
4
6
  # mock Honeybadger
5
7
  end
6
8
 
7
9
  RSpec.describe UniformNotifier::HoneybadgerNotifier do
8
- it "should not notify honeybadger" do
9
- expect(UniformNotifier::HoneybadgerNotifier.out_of_channel_notify(:title => "notify honeybadger")).to be_nil
10
+ it 'should not notify honeybadger' do
11
+ expect(UniformNotifier::HoneybadgerNotifier.out_of_channel_notify(title: 'notify honeybadger')).to be_nil
10
12
  end
11
13
 
12
- it "should notify honeybadger" do
13
- expect(Honeybadger).to receive(:notify).with(UniformNotifier::Exception.new("notify honeybadger"), {})
14
+ it 'should notify honeybadger' do
15
+ expect(Honeybadger).to receive(:notify).with(UniformNotifier::Exception.new('notify honeybadger'), {})
14
16
 
15
17
  UniformNotifier.honeybadger = true
16
- UniformNotifier::HoneybadgerNotifier.out_of_channel_notify(:title => "notify honeybadger")
18
+ UniformNotifier::HoneybadgerNotifier.out_of_channel_notify(title: 'notify honeybadger')
17
19
  end
18
20
 
19
- it "should notify honeybadger" do
20
- expect(Honeybadger).to receive(:notify).with(UniformNotifier::Exception.new("notify honeybadger"), :foo => :bar)
21
+ it 'should notify honeybadger' do
22
+ expect(Honeybadger).to receive(:notify).with(UniformNotifier::Exception.new('notify honeybadger'), foo: :bar)
21
23
 
22
- UniformNotifier.honeybadger = { :foo => :bar }
23
- UniformNotifier::HoneybadgerNotifier.out_of_channel_notify("notify honeybadger")
24
+ UniformNotifier.honeybadger = { foo: :bar }
25
+ UniformNotifier::HoneybadgerNotifier.out_of_channel_notify('notify honeybadger')
24
26
  end
25
27
  end
@@ -1,16 +1,36 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  RSpec.describe UniformNotifier::JavascriptAlert do
4
- it "should not notify message" do
5
- expect(UniformNotifier::JavascriptAlert.inline_notify(:title => "javascript alert!")).to be_nil
6
+ it 'should not notify message' do
7
+ expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to be_nil
6
8
  end
7
9
 
8
- it "should notify message" do
10
+ it 'should notify message' do
9
11
  UniformNotifier.alert = true
10
- expect(UniformNotifier::JavascriptAlert.inline_notify(:title => "javascript alert!")).to eq <<-CODE
11
- <script type="text/javascript">/*<![CDATA[*/
12
- alert( "javascript alert!" );
13
- /*]]>*/</script>
14
- CODE
12
+ expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to eq <<~CODE
13
+ <script type="text/javascript">/*<![CDATA[*/
14
+ alert( "javascript alert!" );
15
+ /*]]>*/</script>
16
+ CODE
17
+ end
18
+
19
+ it 'should accept custom attributes' do
20
+ UniformNotifier.alert = { attributes: { nonce: 'my-nonce', 'data-key' => :value } }
21
+ expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to eq <<~CODE
22
+ <script type="text/javascript" nonce="my-nonce" data-key="value">/*<![CDATA[*/
23
+ alert( "javascript alert!" );
24
+ /*]]>*/</script>
25
+ CODE
26
+ end
27
+
28
+ it 'should have default attributes if no attributes settings exist' do
29
+ UniformNotifier.alert = {}
30
+ expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to eq <<~CODE
31
+ <script type="text/javascript">/*<![CDATA[*/
32
+ alert( "javascript alert!" );
33
+ /*]]>*/</script>
34
+ CODE
15
35
  end
16
36
  end
@@ -1,25 +1,63 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  RSpec.describe UniformNotifier::JavascriptConsole do
4
- it "should not notify message" do
5
- expect(UniformNotifier::JavascriptConsole.inline_notify(:title => "javascript console!")).to be_nil
6
+ it 'should not notify message' do
7
+ expect(UniformNotifier::JavascriptConsole.inline_notify(title: 'javascript console!')).to be_nil
6
8
  end
7
9
 
8
- it "should notify message" do
10
+ it 'should notify message' do
9
11
  UniformNotifier.console = true
10
- expect(UniformNotifier::JavascriptConsole.inline_notify(:title => "javascript console!")).to eq <<-CODE
11
- <script type="text/javascript">/*<![CDATA[*/
12
- if (typeof(console) !== 'undefined' && console.log) {
13
- if (console.groupCollapsed && console.groupEnd) {
14
- console.groupCollapsed(#{"Uniform Notifier".inspect});
15
- console.log(#{"javascript console!".inspect});
16
- console.groupEnd();
17
- } else {
18
- console.log(#{"javascript console!".inspect});
19
- }
20
- }
21
-
22
- /*]]>*/</script>
12
+ expect(UniformNotifier::JavascriptConsole.inline_notify(title: 'javascript console!')).to eq <<~CODE
13
+ <script type="text/javascript">/*<![CDATA[*/
14
+ if (typeof(console) !== 'undefined' && console.log) {
15
+ if (console.groupCollapsed && console.groupEnd) {
16
+ console.groupCollapsed(#{'Uniform Notifier'.inspect});
17
+ console.log(#{'javascript console!'.inspect});
18
+ console.groupEnd();
19
+ } else {
20
+ console.log(#{'javascript console!'.inspect});
21
+ }
22
+ }
23
+
24
+ /*]]>*/</script>
25
+ CODE
26
+ end
27
+
28
+ it 'should accept custom attributes' do
29
+ UniformNotifier.console = { attributes: { nonce: 'my-nonce', 'data-key' => :value } }
30
+ expect(UniformNotifier::JavascriptConsole.inline_notify(title: 'javascript console!')).to eq <<~CODE
31
+ <script type="text/javascript" nonce="my-nonce" data-key="value">/*<![CDATA[*/
32
+ if (typeof(console) !== 'undefined' && console.log) {
33
+ if (console.groupCollapsed && console.groupEnd) {
34
+ console.groupCollapsed(#{'Uniform Notifier'.inspect});
35
+ console.log(#{'javascript console!'.inspect});
36
+ console.groupEnd();
37
+ } else {
38
+ console.log(#{'javascript console!'.inspect});
39
+ }
40
+ }
41
+
42
+ /*]]>*/</script>
43
+ CODE
44
+ end
45
+
46
+ it 'should have default attributes if no attributes settings exist' do
47
+ UniformNotifier.console = {}
48
+ expect(UniformNotifier::JavascriptConsole.inline_notify(title: 'javascript console!')).to eq <<~CODE
49
+ <script type="text/javascript">/*<![CDATA[*/
50
+ if (typeof(console) !== 'undefined' && console.log) {
51
+ if (console.groupCollapsed && console.groupEnd) {
52
+ console.groupCollapsed(#{'Uniform Notifier'.inspect});
53
+ console.log(#{'javascript console!'.inspect});
54
+ console.groupEnd();
55
+ } else {
56
+ console.log(#{'javascript console!'.inspect});
57
+ }
58
+ }
59
+
60
+ /*]]>*/</script>
23
61
  CODE
24
62
  end
25
63
  end