https://github.com/tether/analytics-ruby-mock
Capture all calls to segment.io and prevent them from being sent
https://github.com/tether/analytics-ruby-mock
Last synced: about 1 year ago
JSON representation
Capture all calls to segment.io and prevent them from being sent
- Host: GitHub
- URL: https://github.com/tether/analytics-ruby-mock
- Owner: tether
- License: mit
- Created: 2013-09-20T21:31:19.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2015-07-15T10:38:59.000Z (almost 11 years ago)
- Last Synced: 2024-03-14T23:06:55.491Z (over 2 years ago)
- Language: Ruby
- Size: 225 KB
- Stars: 1
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
analytics-ruby-mock
===================
Capture all calls to Segment.io and prevent them from going to the server. Great for keeping your tests connection free!
Installation
----
```
gem install analytics_ruby_mock
```
Usage
----
Add `analytics_ruby_mock` to your gemfile:
```ruby
gem 'analytics_ruby_mock', group: :test
```
Require analytics_ruby_mock in your `spec_helper`:
```ruby
require 'analytics_ruby_mock'
```
That's it!
Asserting on Analytics
----
Analytics Ruby Mock provides you with the ability to test whether an Analytics call has occurred during your tests.
The following accessors are available for you to check against: `track_calls`, `identify_calls`, and `alias_calls`.
All 3 methods collect the options passed to their respective calls and holds them in an array. Here's an example usage:
```ruby
describe 'show' do
before :each do
get :show, id: @company.id
end
it "calls track for analytics" do
Analytics.track_calls.should == [
{ event: '...', properties: '...' }
]
end
end
```
There's an additional helper for `tracked_events`. It provides an array of any `event` option that occurred during a track
request _(this only applies to `track`, and not `identify` or `alias`)_
```ruby
it "records 'User Viewed Company Page' as an event" do
Analtics.track(event: 'User Viewed Company Page')
Analytics.tracked_events.should == ['User Viewed Company Page']
end
```
You'll need to clear the collected data at the end of your tests. You can do that by calling `Analytics.clear`. We
keep that call in our `spec_helper`:
```ruby
config.after(:each) do
Analytics.clear
end
```
_Future plans would be to move that into a session so that the `clear` could be removed._
Debugging
----
If you'd like to see your calls output to console call the `debug` method:
```ruby
Analytics.debug
```
You'll get an output message any time a method on Analytics is called.
===
Proudly brought to you by [PetroFeed](http://PetroFeed.com). Pull requests and issues always welcome. :kissing_heart:
