spec/pushpop-keen_spec.rb in pushpop-keen-0.2 vs spec/pushpop-keen_spec.rb in pushpop-keen-0.3

- old
+ new

@@ -2,81 +2,85 @@ describe Pushpop::Keen do describe '#configure' do - it 'should set various params' do + it 'sets various params' do step = Pushpop::Keen.new do event_collection 'pageviews' analysis_type 'count' timeframe 'last_3_days' target_property 'trinkets' group_by 'referer' interval 'hourly' + max_age '300' filters [{ property_value: 'referer', operator: 'ne', property_value: 'yahoo.com' }] steps [{ event_collection: 'pageviews', actor_property: 'user.id' }] analyses [{ analysis_type: 'count' }] end step.configure - step._event_collection.should == 'pageviews' - step._analysis_type.should == 'count' - step._timeframe.should == 'last_3_days' - step._group_by.should == 'referer' - step._interval.should == 'hourly' - step._steps.should == [{ + expect(step._event_collection).to eq('pageviews') + expect(step._analysis_type).to eq('count') + expect(step._timeframe).to eq('last_3_days') + expect(step._group_by).to eq('referer') + expect(step._interval).to eq('hourly') + expect(step._max_age).to eq('300') + expect(step._steps).to eq([{ event_collection: 'pageviews', actor_property: 'user.id' - }] - step._analyses.should == [{ analysis_type: 'count' }] + }]) + expect(step._analyses).to eq([{ analysis_type: 'count' }]) end end describe '#record' do - it 'should record an event with properties' do + it 'records an event with properties' do step = Pushpop::Keen.new do record 'Pageview', useragent: 'Chrome' end expect(Keen).to receive(:publish).with('Pageview', useragent: 'Chrome') step.run end end describe '#run' do - it 'should run the query based on the analysis type' do - Keen.stub(:count).with('pageviews', { - timeframe: 'last_3_days' - }).and_return(365) + it 'runs the query based on the analysis type' do + allow(Keen).to receive(:count) { 365 } + #Keen.stub(:count).with('pageviews', { + # timeframe: 'last_3_days' + #}).and_return(365) step = Pushpop::Keen.new('one') do event_collection 'pageviews' analysis_type 'count' timeframe 'last_3_days' end + response = step.run - response.should == 365 + expect(response).to eq(365) end - it 'should not try to run a query if the analysis type isnt set' do + it 'don\'t run a query if the analysis type isnt set' do step = Pushpop::Keen.new do group_by 'something' end expect(Keen).not_to receive(:send) expect(Keen).not_to receive(:funnel) step.run end - it 'should run funnels directly, instead of using send' do + it 'run funnels directly, instead of using send' do step = Pushpop::Keen.new('one') do analysis_type 'funnel' steps [ { actor_property: 'uuid', @@ -97,11 +101,11 @@ step.run end end describe '#to_analysis_options' do - it 'should include various options' do + it 'includes various options' do step = Pushpop::Keen.new('one') do end step._timeframe = 'last_4_days' step._group_by = 'referer' step._target_property = 'trinkets' step._interval = 'hourly' @@ -109,25 +113,26 @@ operator: 'ne', property_value: 'yahoo.com' }] step._steps = [{ event_collection: 'pageviews', actor_property: 'user.id' }] step._analyses = [{ analysis_type: 'count' }] - step.to_analysis_options.should == { + + expect(step.to_analysis_options).to eq({ timeframe: 'last_4_days', target_property: 'trinkets', group_by: 'referer', interval: 'hourly', filters: [{ property_value: 'referer', operator: 'ne', property_value: 'yahoo.com' }], steps: [{ event_collection: 'pageviews', actor_property: 'user.id' }], analyses: [{ analysis_type: 'count' }] - } + }) end - it 'should not include nils' do + it 'doesn\'t include nils' do step = Pushpop::Keen.new('one') do end - step.to_analysis_options.should == {} + expect(step.to_analysis_options).to eq({}) end end end