pusher-fake 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,35 +26,66 @@ describe PusherFake, ".configuration" do
26
26
 
27
27
  it "initializes a configuration object" do
28
28
  subject.configuration
29
- PusherFake::Configuration.should have_received(:new)
29
+
30
+ expect(PusherFake::Configuration).to have_received(:new)
30
31
  end
31
32
 
32
33
  it "memoizes the configuration" do
33
- subject.configuration
34
- subject.configuration
35
- PusherFake::Configuration.should have_received(:new).once
34
+ 2.times { subject.configuration }
35
+
36
+ expect(PusherFake::Configuration).to have_received(:new).once
36
37
  end
37
38
 
38
39
  it "returns the configuration" do
39
- subject.configuration.should == configuration
40
+ expect(subject.configuration).to eq(configuration)
40
41
  end
41
42
  end
42
43
 
43
44
  describe PusherFake, ".javascript" do
44
- let(:options) { { custom: "option" } }
45
45
  let(:configuration) { subject.configuration }
46
46
 
47
47
  subject { PusherFake }
48
48
 
49
49
  it "returns JavaScript setting the host and port to the configured options" do
50
- arguments = [configuration.key, configuration.to_options].map(&:to_json).join(",")
50
+ arguments = [configuration.key, configuration.to_options].map(&:to_json).join(",")
51
+ javascript = subject.javascript
51
52
 
52
- subject.javascript.should == "new Pusher(#{arguments})"
53
+ expect(javascript).to eq("new Pusher(#{arguments})")
53
54
  end
54
55
 
55
56
  it "supports passing custom options" do
56
- arguments = [configuration.key, configuration.to_options(options)].map(&:to_json).join(",")
57
+ options = { custom: "option" }
58
+ arguments = [configuration.key, configuration.to_options(options)].map(&:to_json).join(",")
59
+ javascript = subject.javascript(options)
60
+
61
+ expect(javascript).to eq("new Pusher(#{arguments})")
62
+ end
63
+ end
64
+
65
+ describe PusherFake, ".log" do
66
+ let(:logger) { stub(:<< => "") }
67
+ let(:message) { "Hello world." }
68
+ let(:configuration) { subject.configuration }
69
+
70
+ subject { PusherFake }
71
+
72
+ before do
73
+ configuration.logger = logger
74
+ end
75
+
76
+ it "forwards message to logger when verbose" do
77
+ configuration.verbose = true
78
+
79
+ subject.log(message)
80
+
81
+ expect(logger).to have_received(:<<).with(message + "\n").once
82
+ end
83
+
84
+ it "does not forward message when not verbose" do
85
+ configuration.verbose = false
86
+
87
+ subject.log(message)
57
88
 
58
- subject.javascript(options).should == "new Pusher(#{arguments})"
89
+ expect(logger).to have_received(:<<).never
59
90
  end
60
91
  end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,8 @@ Dir[File.expand_path("../support/**/*.rb", __FILE__)].each do |file|
7
7
  end
8
8
 
9
9
  RSpec.configure do |config|
10
- config.mock_with :mocha
11
- config.include(ConfigurationHelper)
10
+ config.mock_with :mocha
11
+ config.expect_with :rspec do |rspec|
12
+ rspec.syntax = :expect
13
+ end
12
14
  end
@@ -1,44 +1,17 @@
1
- module ConfigurationHelper
2
- class ConfigurationOption
3
- def initialize(option)
4
- @option = option
5
- end
6
-
7
- def matches?(configuration)
8
- @configuration = configuration
9
- @configuration.respond_to?(@option).should == true
10
-
11
- if instance_variables.include?(:@default)
12
- actual = @configuration.__send__(@option)
13
-
14
- if @default.is_a?(Hash)
15
- @default.each do |key, value|
16
- actual[key].should == value
17
- end
18
- else
19
- actual.should == @default
20
- end
21
- end
22
-
23
- @configuration.__send__(:"#{@option}=", "value")
24
- @configuration.__send__(@option).should == "value"
25
- end
26
-
27
- def with_default(default)
28
- @default = default
29
-
30
- self
31
- end
1
+ RSpec::Matchers.define :have_configuration_option do |option|
2
+ match do |configuration|
3
+ configuration.respond_to?(option) &&
4
+ configuration.respond_to?("#{option}=") &&
5
+ (@default.nil? || configuration.public_send(option) == @default)
6
+ end
32
7
 
33
- def failure_message
34
- description = "expected #{@configuration} to have"
35
- description << " configuration option #{@option.inspect}"
36
- description << " with a default of #{@default.inspect}" if instance_variables.include?("@default")
37
- description
38
- end
8
+ chain :with_default do |default|
9
+ @default = default
39
10
  end
40
11
 
41
- def have_configuration_option(option)
42
- ConfigurationOption.new(option)
12
+ failure_message_for_should do |configuration|
13
+ description = "expected configuration to have #{option.inspect} option"
14
+ description << " with a default of #{@default.inspect}" unless @default.nil?
15
+ description
43
16
  end
44
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher-fake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Dunn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-16 00:00:00.000000000 Z
11
+ date: 2014-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -100,20 +100,6 @@ dependencies:
100
100
  - - '='
101
101
  - !ruby/object:Gem::Version
102
102
  version: 1.1.1
103
- - !ruby/object:Gem::Dependency
104
- name: coveralls
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - '='
108
- - !ruby/object:Gem::Version
109
- version: 0.7.0
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - '='
115
- - !ruby/object:Gem::Version
116
- version: 0.7.0
117
103
  - !ruby/object:Gem::Dependency
118
104
  name: cucumber
119
105
  requirement: !ruby/object:Gem::Requirement
@@ -162,14 +148,14 @@ dependencies:
162
148
  requirements:
163
149
  - - '='
164
150
  - !ruby/object:Gem::Version
165
- version: 3.0.0
151
+ version: 3.1.1
166
152
  type: :development
167
153
  prerelease: false
168
154
  version_requirements: !ruby/object:Gem::Requirement
169
155
  requirements:
170
156
  - - '='
171
157
  - !ruby/object:Gem::Version
172
- version: 3.0.0
158
+ version: 3.1.1
173
159
  - !ruby/object:Gem::Dependency
174
160
  name: rspec
175
161
  requirement: !ruby/object:Gem::Requirement