Skip to content

Commit 2de5f4b

Browse files
committed
update specs to expect syntax
1 parent 629b16c commit 2de5f4b

File tree

3 files changed

+128
-128
lines changed

3 files changed

+128
-128
lines changed

spec/channel_spec.rb

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def stub_post_to_raise(e)
2828

2929
describe '#trigger!' do
3030
it "should use @client.trigger internally" do
31-
@client.should_receive(:trigger)
31+
expect(@client).to receive(:trigger)
3232
@channel.trigger('new_event', 'Some data')
3333
end
3434
end
@@ -37,47 +37,47 @@ def stub_post_to_raise(e)
3737
it "should log failure if error raised in http call" do
3838
stub_post_to_raise(HTTPClient::BadResponseError)
3939

40-
Pusher.logger.should_receive(:error).with("Exception from WebMock (HTTPClient::BadResponseError) (Pusher::HTTPError)")
41-
Pusher.logger.should_receive(:debug) #backtrace
40+
expect(Pusher.logger).to receive(:error).with("Exception from WebMock (HTTPClient::BadResponseError) (Pusher::HTTPError)")
41+
expect(Pusher.logger).to receive(:debug) #backtrace
4242
channel = Pusher::Channel.new(@client.url, 'test_channel', @client)
4343
channel.trigger('new_event', 'Some data')
4444
end
4545

4646
it "should log failure if Pusher returns an error response" do
4747
stub_post 401, "some signature info"
48-
Pusher.logger.should_receive(:error).with("some signature info (Pusher::AuthenticationError)")
49-
Pusher.logger.should_receive(:debug) #backtrace
48+
expect(Pusher.logger).to receive(:error).with("some signature info (Pusher::AuthenticationError)")
49+
expect(Pusher.logger).to receive(:debug) #backtrace
5050
channel = Pusher::Channel.new(@client.url, 'test_channel', @client)
5151
channel.trigger('new_event', 'Some data')
5252
end
5353
end
5454

5555
describe "#initialization" do
5656
it "should not be too long" do
57-
lambda { @client['b'*201] }.should raise_error(Pusher::Error)
57+
expect { @client['b'*201] }.to raise_error(Pusher::Error)
5858
end
5959

6060
it "should not use bad characters" do
61-
lambda { @client['*^!±`/""'] }.should raise_error(Pusher::Error)
61+
expect { @client['*^!±`/""'] }.to raise_error(Pusher::Error)
6262
end
6363
end
6464

6565
describe "#trigger_async" do
6666
it "should use @client.trigger_async internally" do
67-
@client.should_receive(:trigger_async)
67+
expect(@client).to receive(:trigger_async)
6868
@channel.trigger_async('new_event', 'Some data')
6969
end
7070
end
7171

7272
describe '#info' do
7373
it "should call the Client#channel_info" do
74-
@client.should_receive(:get).with("/channels/mychannel", anything)
74+
expect(@client).to receive(:get).with("/channels/mychannel", anything)
7575
@channel = @client['mychannel']
7676
@channel.info
7777
end
7878

7979
it "should assemble the requested attributes into the info option" do
80-
@client.should_receive(:get).with(anything, {
80+
expect(@client).to receive(:get).with(anything, {
8181
:info => "user_count,connection_count"
8282
})
8383
@channel = @client['presence-foo']
@@ -87,7 +87,7 @@ def stub_post_to_raise(e)
8787

8888
describe '#users' do
8989
it "should call the Client#channel_users" do
90-
@client.should_receive(:get).with("/channels/presence-mychannel/users").and_return({:users => {'id' => '4'}})
90+
expect(@client).to receive(:get).with("/channels/presence-mychannel/users").and_return({:users => {'id' => '4'}})
9191
@channel = @client['presence-mychannel']
9292
@channel.users
9393
end
@@ -101,28 +101,28 @@ def authentication_string(*data)
101101
it "should return an authentication string given a socket id" do
102102
auth = @channel.authentication_string('1.1')
103103

104-
auth.should == '12345678900000001:02259dff9a2a3f71ea8ab29ac0c0c0ef7996c8f3fd3702be5533f30da7d7fed4'
104+
expect(auth).to eq('12345678900000001:02259dff9a2a3f71ea8ab29ac0c0c0ef7996c8f3fd3702be5533f30da7d7fed4')
105105
end
106106

107107
it "should raise error if authentication is invalid" do
108108
[nil, ''].each do |invalid|
109-
authentication_string(invalid).should raise_error Pusher::Error
109+
expect(authentication_string(invalid)).to raise_error Pusher::Error
110110
end
111111
end
112112

113113
describe 'with extra string argument' do
114114
it 'should be a string or nil' do
115-
authentication_string('1.1', 123).should raise_error Pusher::Error
116-
authentication_string('1.1', {}).should raise_error Pusher::Error
115+
expect(authentication_string('1.1', 123)).to raise_error Pusher::Error
116+
expect(authentication_string('1.1', {})).to raise_error Pusher::Error
117117

118-
authentication_string('1.1', 'boom').should_not raise_error
119-
authentication_string('1.1', nil).should_not raise_error
118+
expect(authentication_string('1.1', 'boom')).not_to raise_error
119+
expect(authentication_string('1.1', nil)).not_to raise_error
120120
end
121121

122122
it "should return an authentication string given a socket id and custom args" do
123123
auth = @channel.authentication_string('1.1', 'foobar')
124124

125-
auth.should == "12345678900000001:#{hmac(@client.secret, "1.1:test_channel:foobar")}"
125+
expect(auth).to eq("12345678900000001:#{hmac(@client.secret, "1.1:test_channel:foobar")}")
126126
end
127127
end
128128
end
@@ -133,36 +133,36 @@ def authentication_string(*data)
133133
end
134134

135135
it 'should return a hash with signature including custom data and data as json string' do
136-
MultiJson.stub(:encode).with(@custom_data).and_return 'a json string'
136+
allow(MultiJson).to receive(:encode).with(@custom_data).and_return 'a json string'
137137

138138
response = @channel.authenticate('1.1', @custom_data)
139139

140-
response.should == {
140+
expect(response).to eq({
141141
:auth => "12345678900000001:#{hmac(@client.secret, "1.1:test_channel:a json string")}",
142142
:channel_data => 'a json string'
143-
}
143+
})
144144
end
145145

146146
it 'should fail on invalid socket_ids' do
147-
lambda {
147+
expect {
148148
@channel.authenticate('1.1:')
149-
}.should raise_error Pusher::Error
149+
}.to raise_error Pusher::Error
150150

151-
lambda {
151+
expect {
152152
@channel.authenticate('1.1foo', 'channel')
153-
}.should raise_error Pusher::Error
153+
}.to raise_error Pusher::Error
154154

155-
lambda {
155+
expect {
156156
@channel.authenticate(':1.1')
157-
}.should raise_error Pusher::Error
157+
}.to raise_error Pusher::Error
158158

159-
lambda {
159+
expect {
160160
@channel.authenticate('foo1.1', 'channel')
161-
}.should raise_error Pusher::Error
161+
}.to raise_error Pusher::Error
162162

163-
lambda {
163+
expect {
164164
@channel.authenticate('foo', 'channel')
165-
}.should raise_error Pusher::Error
165+
}.to raise_error Pusher::Error
166166
end
167167
end
168168
end

0 commit comments

Comments
 (0)