Permalink
Browse files

Fix broken windows by standardizing use of strings

by using single-quoted strings unless double-quoted are needed. Again,
sorry for the anal-retentiveness.

http://i1.kym-cdn.com/photos/images/original/000/243/561/afc.gif
  • Loading branch information...
1 parent 658c271 commit 322ab07907c10833b49559f2536f9af3fcadcfa1 @stevenharman stevenharman committed Mar 30, 2012
View
2 Rakefile
@@ -1,5 +1,5 @@
#!/usr/bin/env rake
-require "bundler/gem_tasks"
+require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
View
10 lib/grocer.rb
@@ -1,8 +1,8 @@
-require_relative "grocer/connection"
-require_relative "grocer/feedback"
-require_relative "grocer/notification"
-require_relative "grocer/pusher"
-require_relative "grocer/version"
+require_relative 'grocer/connection'
+require_relative 'grocer/feedback'
+require_relative 'grocer/notification'
+require_relative 'grocer/pusher'
+require_relative 'grocer/version'
module Grocer
View
4 lib/grocer/failed_delivery_attempt.rb
@@ -1,4 +1,4 @@
-require_relative "invalid_format_error"
+require_relative 'invalid_format_error'
module Grocer
class FailedDeliveryAttempt
@@ -10,7 +10,7 @@ def initialize(binary_tuple)
# N => 4 byte timestamp
# n => 2 byte token_length
# H64 => 32 byte device_token
- seconds, _, @device_token = binary_tuple.unpack("NnH64")
+ seconds, _, @device_token = binary_tuple.unpack('NnH64')
raise InvalidFormatError unless seconds && @device_token
@timestamp = Time.at(seconds)
end
View
2 lib/grocer/feedback.rb
@@ -1,4 +1,4 @@
-require_relative "failed_delivery_attempt"
+require_relative 'failed_delivery_attempt'
module Grocer
class Feedback
View
8 lib/grocer/notification.rb
@@ -1,5 +1,5 @@
-require "json"
-require_relative "no_payload_error"
+require 'json'
+require_relative 'no_payload_error'
module Grocer
class Notification
@@ -17,7 +17,7 @@ def to_bytes
validate_payload
payload = encoded_payload
- [1, identifier, expiry_epoch_time, device_token_length, sanitized_device_token, payload.length].pack("CNNnH64n") << payload
+ [1, identifier, expiry_epoch_time, device_token_length, sanitized_device_token, payload.length].pack('CNNnH64n') << payload
end
private
@@ -44,7 +44,7 @@ def expiry_epoch_time
end
def sanitized_device_token
- device_token.tr(" ", "") if device_token
+ device_token.tr(' ', '') if device_token
end
def device_token_length
View
6 lib/grocer/ssl_connection.rb
@@ -1,6 +1,6 @@
-require "socket"
-require "openssl"
-require "forwardable"
+require 'socket'
+require 'openssl'
+require 'forwardable'
module Grocer
class SSLConnection
View
2 lib/grocer/version.rb
@@ -1,3 +1,3 @@
module Grocer
- VERSION = "0.0.1"
+ VERSION = '0.0.1'
end
View
2 spec/grocer/connection_spec.rb
@@ -4,7 +4,7 @@
describe Grocer::Connection do
subject { described_class.new(connection_options) }
let(:connection_options) { { certificate: '/path/to/cert.pom' } }
- let(:ssl) { stub_everything("SSLConnection") }
+ let(:ssl) { stub_everything('SSLConnection') }
before do
Grocer::SSLConnection.stubs(:new).returns(ssl)
end
View
12 spec/grocer/failed_delivery_attempt_spec.rb
@@ -3,18 +3,18 @@
describe Grocer::FailedDeliveryAttempt do
let(:timestamp) { Time.utc(1995, 12, 21) }
- let(:device_token) { "fe15a27d5df3c34778defb1f4f3980265cc52c0c047682223be59fb68500a9a2" }
- let(:binary_tuple) { [timestamp.to_i, 32, device_token].pack("NnH64") }
- let(:invalid_binary_tuple) { "totally not the right format" }
+ let(:device_token) { 'fe15a27d5df3c34778defb1f4f3980265cc52c0c047682223be59fb68500a9a2' }
+ let(:binary_tuple) { [timestamp.to_i, 32, device_token].pack('NnH64') }
+ let(:invalid_binary_tuple) { 'totally not the right format' }
- describe "decoding" do
- it "accepts a binary tuple and sets each attribute" do
+ describe 'decoding' do
+ it 'accepts a binary tuple and sets each attribute' do
failed_delivery_attempt = described_class.new(binary_tuple)
failed_delivery_attempt.timestamp.should == timestamp
failed_delivery_attempt.device_token.should == device_token
end
- it "raises an exception when there are problems decoding" do
+ it 'raises an exception when there are problems decoding' do
-> { described_class.new(invalid_binary_tuple) }.should
raise_error(Grocer::InvalidFormatError)
end
View
14 spec/grocer/feedback_spec.rb
@@ -1,30 +1,30 @@
-require "spec_helper"
-require "grocer/feedback"
+require 'spec_helper'
+require 'grocer/feedback'
describe Grocer::Feedback do
def stub_feedback
# "Reads" two failed deliveries: one on Jan 1; the other on Jan 2
connection.stubs(:read).
with(38).
- returns([jan1.to_i, 32, device_token].pack("NnH64")).
+ returns([jan1.to_i, 32, device_token].pack('NnH64')).
then.
- returns([jan2.to_i, 32, device_token].pack("NnH64")).
+ returns([jan2.to_i, 32, device_token].pack('NnH64')).
then.
returns(nil)
end
let(:connection) { stub_everything }
let(:jan1) { Time.utc(2012, 1, 1) }
let(:jan2) { Time.utc(2012, 1, 2) }
- let(:device_token) { "fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2" }
+ let(:device_token) { 'fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2' }
subject { described_class.new(connection) }
- it "is enumerable" do
+ it 'is enumerable' do
subject.should be_kind_of(Enumerable)
end
- it "reads failed delivery attempt messages from the connection" do
+ it 'reads failed delivery attempt messages from the connection' do
stub_feedback
delivery_attempts = subject.to_a
View
56 spec/grocer/notification_spec.rb
@@ -2,76 +2,76 @@
require 'grocer/notification'
describe Grocer::Notification do
- describe "binary format" do
+ describe 'binary format' do
let(:notification) { described_class.new(payload_options) }
let(:payload_from_bytes) { notification.to_bytes[45..-1] }
let(:payload_dictionary_from_bytes) { JSON.parse(payload_from_bytes, symbolize_names: true) }
let(:payload_options) { { alert: 'hi', badge: 2, sound: 'siren.aiff' } }
subject { notification.to_bytes }
- it "sets the command byte to 1" do
+ it 'sets the command byte to 1' do
subject[0].should == "\x01"
end
- it "defaults the identifer to 0" do
+ it 'defaults the identifer to 0' do
subject[1...5].should == "\x00\x00\x00\x00"
end
- it "allows the identifier to be set" do
+ it 'allows the identifier to be set' do
notification.identifier = 1234
- subject[1...5].should == [1234].pack("N")
+ subject[1...5].should == [1234].pack('N')
end
- it "defaults expiry to zero" do
+ it 'defaults expiry to zero' do
subject[5...9].should == "\x00\x00\x00\x00"
end
- it "allows the expiry to be set" do
+ it 'allows the expiry to be set' do
expiry = notification.expiry = Time.utc(2013, 3, 24, 12, 34, 56)
- subject[5...9].should == [expiry.to_i].pack("N")
+ subject[5...9].should == [expiry.to_i].pack('N')
end
- it "encodes the device token length as 32" do
+ it 'encodes the device token length as 32' do
subject[9...11].should == "\x00\x20"
end
- it "encodes the device token as a 256-bit integer" do
- token = notification.device_token = "fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2"
- subject[11...43].should == ["fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2"].pack("H*")
+ it 'encodes the device token as a 256-bit integer' do
+ token = notification.device_token = 'fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2'
+ subject[11...43].should == ['fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2'].pack('H*')
end
- it "as a convenience, flattens the device token to remove spaces" do
- token = notification.device_token = "fe15 a27d 5df3c3 4778defb1f4f3880265cc52c0c047682223be59fb68500a9a2"
- subject[11...43].should == ["fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2"].pack("H*")
+ it 'as a convenience, flattens the device token to remove spaces' do
+ token = notification.device_token = 'fe15 a27d 5df3c3 4778defb1f4f3880265cc52c0c047682223be59fb68500a9a2'
+ subject[11...43].should == ['fe15a27d5df3c34778defb1f4f3880265cc52c0c047682223be59fb68500a9a2'].pack('H*')
end
- it "encodes the payload length" do
- notification.alert = "Hello World!"
- subject[43...45].should == [payload_from_bytes.length].pack("n")
+ it 'encodes the payload length' do
+ notification.alert = 'Hello World!'
+ subject[43...45].should == [payload_from_bytes.length].pack('n')
end
- it "encodes alert as part of the payload" do
- notification.alert = "Hello World!"
- payload_dictionary_from_bytes[:aps][:alert].should == "Hello World!"
+ it 'encodes alert as part of the payload' do
+ notification.alert = 'Hello World!'
+ payload_dictionary_from_bytes[:aps][:alert].should == 'Hello World!'
end
- it "encodes badge as part of the payload" do
+ it 'encodes badge as part of the payload' do
notification.badge = 42
payload_dictionary_from_bytes[:aps][:badge].should == 42
end
- it "encodes sound as part of the payload" do
- notification.sound = "siren.aiff"
- payload_dictionary_from_bytes[:aps][:sound].should == "siren.aiff"
+ it 'encodes sound as part of the payload' do
+ notification.sound = 'siren.aiff'
+ payload_dictionary_from_bytes[:aps][:sound].should == 'siren.aiff'
end
- it "encodes custom payload attributes"
+ it 'encodes custom payload attributes'
- context "invalid payload" do
+ context 'invalid payload' do
let(:payload_options) { Hash.new }
- it "raises an error when neither alert nor badge is specified" do
+ it 'raises an error when neither alert nor badge is specified' do
-> { notification.to_bytes }.should raise_error(Grocer::NoPayloadError)
end
end
View
12 spec/grocer/pusher_spec.rb
@@ -1,17 +1,17 @@
-require "spec_helper"
-require "grocer/pusher"
+require 'spec_helper'
+require 'grocer/pusher'
describe Grocer::Pusher do
let(:connection) { stub_everything }
subject { described_class.new(connection) }
- describe "#push" do
- it "serializes a notification and sends it via the connection" do
- notification = stub(:to_bytes => "abc123")
+ describe '#push' do
+ it 'serializes a notification and sends it via the connection' do
+ notification = stub(:to_bytes => 'abc123')
subject.push(notification)
- connection.should have_received(:write).with("abc123")
+ connection.should have_received(:write).with('abc123')
end
end
end
View
40 spec/grocer/ssl_connection_spec.rb
@@ -1,5 +1,5 @@
-require "spec_helper"
-require "grocer/ssl_connection"
+require 'spec_helper'
+require 'grocer/ssl_connection'
describe Grocer::SSLConnection do
def stub_sockets
@@ -8,7 +8,7 @@ def stub_sockets
end
def stub_certificate
- example_data = File.read(File.dirname(__FILE__) + "/../fixtures/example.pem")
+ example_data = File.read(File.dirname(__FILE__) + '/../fixtures/example.pem')
File.stubs(:read).with(connection_options[:certificate]).returns(example_data)
end
@@ -17,72 +17,72 @@ def stub_certificate
let(:connection_options) {
{
- certificate: "/path/to/cert.pem",
- passphrase: "abc123",
- gateway: "gateway.push.highgroove.com",
+ certificate: '/path/to/cert.pem',
+ passphrase: 'abc123',
+ gateway: 'gateway.push.highgroove.com',
port: 1234
}
}
subject { described_class.new(connection_options) }
- describe "configuration" do
- it "is initialized with a certificate" do
+ describe 'configuration' do
+ it 'is initialized with a certificate' do
subject.certificate.should == connection_options[:certificate]
end
- it "is initialized with a passphrase" do
+ it 'is initialized with a passphrase' do
subject.passphrase.should == connection_options[:passphrase]
end
- it "is initialized with a gateway" do
+ it 'is initialized with a gateway' do
subject.gateway.should == connection_options[:gateway]
end
- it "is initialized with a port" do
+ it 'is initialized with a port' do
subject.port.should == connection_options[:port]
end
end
- describe "connecting" do
+ describe 'connecting' do
before do
stub_sockets
stub_certificate
end
- it "sets up an socket connection" do
+ it 'sets up an socket connection' do
subject.connect
TCPSocket.should have_received(:new).with(connection_options[:gateway],
connection_options[:port])
end
- it "sets up an SSL connection" do
+ it 'sets up an SSL connection' do
subject.connect
OpenSSL::SSL::SSLSocket.should have_received(:new).with(mock_socket, anything)
end
end
- describe "writing data" do
+ describe 'writing data' do
before do
stub_sockets
stub_certificate
end
- it "writes data to the SSL connection" do
+ it 'writes data to the SSL connection' do
subject.connect
- subject.write("abc123")
+ subject.write('abc123')
- mock_ssl.should have_received(:write).with("abc123")
+ mock_ssl.should have_received(:write).with('abc123')
end
end
- describe "reading data" do
+ describe 'reading data' do
before do
stub_sockets
stub_certificate
end
- it "reads data from the SSL connection" do
+ it 'reads data from the SSL connection' do
subject.connect
subject.read(42)
View
6 spec/grocer_spec.rb
@@ -26,10 +26,10 @@
end
end
- describe ".pusher" do
- let(:connection_options) { stub("connection options") }
+ describe '.pusher' do
+ let(:connection_options) { stub('connection options') }
before do
- Grocer::Connection.stubs(:new).returns(stub("Connection"))
+ Grocer::Connection.stubs(:new).returns(stub('Connection'))
end
it 'returns a Connection' do

0 comments on commit 322ab07

Please sign in to comment.