Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/trebuchet/state.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Represents the internal, global and thread-unsafe state of Trebuchet
Trebuchet::State = Struct.new(
:visitor_id, :current, :current_block,
:logs, :admin_view, :admin_edit, :time_zone
:logs, :admin_view, :admin_edit, :time_zone,
:author
)
2 changes: 1 addition & 1 deletion lib/trebuchet/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Trebuchet

VERSION = "0.12.0"
VERSION = "0.12.1".freeze

end
44 changes: 27 additions & 17 deletions spec/trebuchet_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require 'spec_helper'

describe Trebuchet do

describe "launch?" do

it "should call launch_at? on feature" do
Trebuchet::Feature.any_instance.should_receive(:launch_at?).once
Trebuchet.new(User.new(1)).launch?('highly_experimental')
end

it "should call launch_at? on feature even if missing user" do
Trebuchet::Feature.any_instance.should_receive(:launch_at?).once
Trebuchet.new(nil).launch?('highly_experimental')
Expand All @@ -26,7 +26,7 @@
t.launch?('waste_of_time')
end
end

describe "launch" do
it "should execute a block" do
times = 0
Expand All @@ -35,50 +35,50 @@
(Trebuchet.new(User.new(3)).launch('highly_experimental') { times += 1 }).should be_false
times.should == 1
end

it "should not blow up if block is missing" do
lambda do
Trebuchet.aim('highly_experimental', :users, [1,2])
Trebuchet.new(User.new(1)).launch('highly_experimental').should be_true
Trebuchet.new(User.new(3)).launch('highly_experimental').should be_false
Trebuchet.new(nil).launch('highly_experimental').should be_false
end.should_not raise_error(LocalJumpError)

end

end

describe "logging" do

before(:all) do
Trebuchet.aim('highly_experimental', :users, [1,2])
Trebuchet.aim('disused', :disabled)
end

before(:each) do
Trebuchet.initialize_logs
end

it "should log" do
Trebuchet.logs.should == {}
Trebuchet.new(User.new(1)).launch?('highly_experimental').should == true
Trebuchet.logs['highly_experimental'].should == true
end

it "should log false/nil" do
Trebuchet.logs['complely_fabricated'] == nil
Trebuchet.logs['disused'].should == nil
Trebuchet.new(User.new(1)).launch?('disused') #.should == false
Trebuchet.logs['disused'].should == false
end

it "it should clear logs" do
Trebuchet.new(User.new(1)).launch?('highly_experimental').should == true
Trebuchet.logs['highly_experimental'].should == true
Trebuchet.initialize_logs
Trebuchet.logs.should == {}
end

it "should log from multiple trebuchet instances" do
Trebuchet.new(User.new(1)).launch?('highly_experimental') #.should == true
Trebuchet.new(User.new(1)).launch?('disused') #.should == false
Expand All @@ -87,7 +87,7 @@
Trebuchet.logs['disused'].should == false
Trebuchet.logs['waste_of_time'].should == false
end

end

describe "exception handling" do
Expand Down Expand Up @@ -122,7 +122,7 @@ class BoomError < StandardError ; end
Trebuchet.exception_handler = lambda { @last_arg = eval local_variables.last.to_s }
Trebuchet.current.launch?("optimism")
@last_arg.should == nil

Trebuchet.exception_handler = lambda { |e| @last_arg = eval local_variables.last.to_s }
Trebuchet.current.launch?("optimism")
@last_arg.should be_a(StandardError)
Expand Down Expand Up @@ -156,5 +156,15 @@ class BoomError < StandardError ; end
end

end


it "stores state variables" do
%i{author admin_view admin_edit time_zone}.each do |key|
begin
Trebuchet.public_send :"#{key}=", 1
expect(Trebuchet.public_send(key)).to eq 1
ensure
Trebuchet.public_send :"#{key}=", nil
end
end
end
end