Skip to content

Commit

Permalink
Updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin French-Owen committed Jan 17, 2013
1 parent 2ff2b0d commit 1e9115f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 47 deletions.
51 changes: 30 additions & 21 deletions spec/client_spec.rb
@@ -1,37 +1,46 @@
require 'analytics'
require 'spec_helper'

secret = 'testsecret'

describe Analytics::Client, '#track' do
describe Analytics::Client do

before(:all) { @client = Analytics::Client.new secret: secret }
describe '#track' do

it 'should error without an event' do
expect { @client.track(user_id: 'user') }.to raise_error(ArgumentError)
end
before(:all) do
@client = Analytics::Client.new secret: AnalyticsHelpers::SECRET
end

it 'should error without a user or session' do
expect { @client.track(event: 'Event') }.to raise_error(ArgumentError)
end
it 'should error without an event' do
expect { @client.track(user_id: 'user') }.to raise_error(ArgumentError)
end

it 'should error without a user or session' do
expect { @client.track(event: 'Event') }.to raise_error(ArgumentError)
end

it 'should not error with the required options' do
@client.track(user_id: 'user',
event: 'Event')
end

it 'should not error with the required options' do
@client.track(user_id: 'user',
event: 'Event')
end

end

describe Analytics::Client, '#identify' do
describe '#identify' do

before(:all) { @client = Analytics::Client.new secret: secret }
before(:all) do
@client = Analytics::Client.new secret: AnalyticsHelpers::SECRET
end

it 'should error without any user id' do
expect { @client.identify({}) }.to raise_error(ArgumentError)
end
it 'should error without any user id' do
expect { @client.identify({}) }.to raise_error(ArgumentError)
end

it 'should not error with the required options' do
@client.identify(user_id: 'user',
properties: { dog: true })
end

it 'should not error with the required options' do
@client.identify(user_id: 'user',
properties: { dog: true })
end

end
Expand Down
7 changes: 3 additions & 4 deletions spec/consumer_spec.rb
@@ -1,7 +1,6 @@
require_relative '../lib/analytics'
require_relative './spec_helper'

require 'analytics'
require 'thread'
require 'spec_helper'

describe Analytics::Consumer do

Expand Down Expand Up @@ -47,7 +46,7 @@
on_error.should_receive(:call).at_most(0).times

queue = Queue.new
queue << AnalyticsHelpers::Raw::TRACK
queue << AnalyticsHelpers::Requested::TRACK
consumer = Analytics::Consumer.new(queue, 'testsecret', { on_error: on_error })
consumer.flush
end
Expand Down
2 changes: 1 addition & 1 deletion spec/module_spec.rb
@@ -1,5 +1,5 @@
require 'analytics'

require 'spec_helper'

describe Analytics, '#init' do

Expand Down
53 changes: 32 additions & 21 deletions spec/spec_helper.rb
Expand Up @@ -3,30 +3,41 @@ module AnalyticsHelpers

SECRET = 'testsecret'

module Raw

TRACK = { event: 'Baked a cake',
userId: 'Bret',
properties: {
type: 'Chocolate',
is_a_lie: true,
layers: 20,
created: Time.new
},
action: 'track'
TRACK = { event: 'Baked a cake',
properties: {
type: 'Chocolate',
is_a_lie: true,
layers: 20,
created: Time.new
}
}

IDENTIFY = { userId: 'Bret',
sessionId: '4815162342',
traits: {
likes_animals: true,
instrument: 'Guitar',
age: 25
},
action: 'identify'
}
end
IDENTIFY = { traits: {
likes_animals: true,
instrument: 'Guitar',
age: 25
},
action: 'identify'
}

USER_ID = 'Bret'
SESSION_ID = '4815162342'

# Hashes sent to the client
module Queued
TRACK = TRACK.merge({ user_id: USER_ID })

IDENTIFY = IDENTIFY.merge({ user_id: USER_ID,
session_id: SESSION_ID })
end

# Hashes which are sent from the consumer
module Requested
TRACK = TRACK.merge({ userId: USER_ID,
action: 'track' })

IDENTIFY = IDENTIFY.merge({ userId: USER_ID,
sessionId: SESSION_ID,
action: 'identify' })
end
end

0 comments on commit 1e9115f

Please sign in to comment.