spec/trakio/track_spec.rb in trakio-ruby-0.1.3 vs spec/trakio/track_spec.rb in trakio-ruby-0.1.4
- old
+ new
@@ -6,21 +6,22 @@
after {
Trakio.default_instance = nil
}
- describe '.track' do
+ describe '#track' do
context "when a distinct_id is provided" do
context "when an event is provided" do
it "sends a track request to api.trak.io" do
stub = stub_request(:post, "https://api.trak.io/v1/track").
with(:body => {
token: 'my_api_token',
data: {
+ time: /.+/,
distinct_id: 'user@example.com',
event: 'my-event'
}
}).to_return(:body => {
status: 'success',
@@ -31,20 +32,21 @@
resp = trakio.track distinct_id: 'user@example.com', event: 'my-event'
expect(resp[:status]).to eql 'success'
expect(resp[:trak_id]).to eql '1234567890'
- stub.should have_been_requested
+ expect(stub).to have_been_requested
end
context "when a channel is provided" do
it "sends a track request to api.trak.io" do
stub = stub_request(:post, "https://api.trak.io/v1/track").
with(:body => {
token: 'my_api_token',
data: {
+ time: /.+/,
distinct_id: 'user@example.com',
event: 'my-event',
channel: 'my-channel'
}
}).to_return(:body => {
@@ -57,11 +59,11 @@
channel: 'my-channel'
expect(resp[:status]).to eql 'success'
expect(resp[:trak_id]).to eql '1234567890'
- stub.should have_been_requested
+ expect(stub).to have_been_requested
end
end
context "when a channel isn't provided and there is one on the instance" do
@@ -69,10 +71,11 @@
it "sends a track request to api.trak.io" do
stub = stub_request(:post, "https://api.trak.io/v1/track").
with(:body => {
token: 'my_api_token',
data: {
+ time: /.+/,
distinct_id: 'user@example.com',
event: 'my-event',
channel: 'my-channel'
}
}).to_return(:body => {
@@ -84,11 +87,11 @@
resp = trakio.track distinct_id: 'user@example.com', event: 'my-event'
expect(resp[:status]).to eql 'success'
expect(resp[:trak_id]).to eql '1234567890'
- stub.should have_been_requested
+ expect(stub).to have_been_requested
end
end
context "when properties are provided" do
@@ -96,10 +99,11 @@
it "sends a track request to api.trak.io" do
stub = stub_request(:post, "https://api.trak.io/v1/track").
with(:body => {
token: 'my_api_token',
data: {
+ time: /.+/,
distinct_id: 'user@example.com',
event: 'my-event',
channel: 'my-channel',
properties: {
foo: 'bar'
@@ -115,11 +119,11 @@
channel: 'my-channel', properties: { foo: 'bar' }
expect(resp[:status]).to eql 'success'
expect(resp[:trak_id]).to eql '1234567890'
- stub.should have_been_requested
+ expect(stub).to have_been_requested
end
end
context "when a time is provided as a DateTime" do
@@ -144,11 +148,11 @@
resp = trakio.track distinct_id: 'user@example.com', event: 'my-event', time: time
expect(resp[:status]).to eql 'success'
expect(resp[:trak_id]).to eql '1234567890'
- stub.should have_been_requested
+ expect(stub).to have_been_requested
end
end
context "when a time is provided as a string" do
@@ -173,11 +177,11 @@
resp = trakio.track distinct_id: 'user@example.com', event: 'my-event', time: time.iso8601
expect(resp[:status]).to eql 'success'
expect(resp[:trak_id]).to eql '1234567890'
- stub.should have_been_requested
+ expect(stub).to have_been_requested
end
end
end
@@ -213,10 +217,11 @@
it "sends a track request to api.trak.io" do
stub = stub_request(:post, "https://api.trak.io/v1/track").
with(:body => {
token: 'my_api_token',
data: {
+ time: /.+/,
distinct_id: 'user@example.com',
event: 'my-event',
}
}).to_return(:body => {
status: 'success',
@@ -224,10 +229,10 @@
}.to_json)
trakio = Trakio.new 'my_api_token', distinct_id: 'user@example.com'
trakio.track event: 'my-event'
- stub.should have_been_requested
+ expect(stub).to have_been_requested
end
end
end