Skip to content

Commit

Permalink
Regularize spec suite options
Browse files Browse the repository at this point in the history
  • Loading branch information
arvicco committed Jul 6, 2012
1 parent abfd4fa commit 3073367
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--colour
--format progress
--color
--format nested
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ib-ruby (0.8.1)
ib-ruby (0.8.2)
activerecord (>= 3.2.0)
bundler (>= 1.1.3)
standalone_migrations
Expand Down
6 changes: 4 additions & 2 deletions spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ with database backend, use:

$ rspec -rdb [spec/specific_spec.rb]

To run using the rails engine integration use:
To run specs using the Rails engine integration use:

$ rspec -rr [spec/specific_spec.rb]

If you run your specs against both Gateway and TWS, you may want to use the following
switch to run specs against TWS port (as opposed to default Gateway port):
switches (by default, TWS port is used):

$ rspec -rgw [spec/specific_spec.rb]
$ rspec -rtws [spec/specific_spec.rb]

# WRITING YOUR OWN INTEGRATION SPECS
Expand Down
4 changes: 4 additions & 0 deletions spec/gw.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
puts 'To run specs against the Gateway port, use:'
puts '$ rspec -rgw spec'

PORT = 4001
2 changes: 1 addition & 1 deletion spec/integration/orders/trades_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def execution_should_be side, opts={}
exec.local_id.should == @order.local_id if @order
exec.exec_id.should be_a String
exec.time.should =~ /\d\d:\d\d:\d\d/
exec.account_name.should == OPTS[:connection][:account_name]
exec.account_name.should == OPTS[:connection][:account]
exec.exchange.should == 'IDEALPRO'
exec.side.should == side
exec.shares.should == 20000
Expand Down
5 changes: 5 additions & 0 deletions spec/my.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# My very specific connection configuration to run specs

ACCOUNT = 'DU118180'
HOST = '10.211.55.2'
PORT = 4001
4 changes: 2 additions & 2 deletions spec/r.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
puts 'To run specs with rails (ActiveRecord), use:'
puts '$ bundle exec rspec -rr spec/ib-ruby/models'
puts '$ rspec -rr spec/ib-ruby/models'

require 'bundler/setup'
require 'combustion'

require 'ib_engine'

Combustion.initialize!
Expand Down
67 changes: 35 additions & 32 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
require 'rspec'
require 'ib-ruby'

PORT ||= 7496 # 4001 for Gateway, 7496 for TWS GUI
# Configure top level option indicating how the test suite should be run

# Top level metadata for test suite level hacking
OPTS ||= {
:verbose => false, #true, # Verbosity of test outputs
:brokertron => false, # Use mock (Brokertron) instead of paper account
:verbose => false, #true, # Run test suite in a verbose mode ?
:brokertron => false, # Use mock (Brokertron) instead of paper account ?
}

pp OPTS

if OPTS[:brokertron]
puts "Using Brokerton free.brokertron.com mock service."
# Connection to mock (Brokertron) account
OPTS[:connection] =
{:client_id => 1111, # Just an arbitrary id
:host => 'free.brokertron.com',
:port=> 10501
}
OPTS[:connection] = {
:client_id => 1111, # Client id that identifies the test suit
:host => 'free.brokertron.com',
:port => 10501
}
else
# Connection to IB PAPER ACCOUNT
OPTS[:connection] =
{:account_name => 'DU60320', # Your IB PAPER ACCOUNT, tests will only run against it
:client_id => 1111, # Just an arbitrary id
:host => '127.0.0.1', # Where your TWS/gateway is located, likely '127.0.0.1'
:port => PORT,
:reuters => true # Subscription to Reuters data enabled ?
}
ACCOUNT ||= 'DU60320'
HOST ||= '127.0.0.1'
PORT ||= 7496

OPTS[:connection] = {
:account => ACCOUNT, # Your IB PAPER ACCOUNT, tests will only run against it
:host => HOST, # Where your TWS/gateway is located, likely '127.0.0.1'
:port => PORT, # 4001 for Gateway, 7496 for TWS GUI
:client_id => 1111, # Client id that identifies the test suit
:reuters => true # Subscription to Reuters data enabled ?
}
end

puts 'Running specs with OPTS:'
pp OPTS

RSpec.configure do |config|
config.exclusion_filter = {
:if => proc do |condition|
t = Time.now.utc
case condition # NB: excludes if condition is false!
when :us_trading_hours
# 09:30 - 16:00 (ET) Mon-Fri 14:30 - 21:00 (UTC)
!(t.wday >= 1 && t.wday <= 5 && t.hour >= 15 && t.hour <= 21)
when :forex_trading_hours
# 17:15 - 17:00 (ET) Sunday-Friday Forex 22:15 - 22:00 (UTC)
!(t.wday > 0 && t.wday < 5 || t.wday == 5 && t.hour < 22)
end
end,
:if => proc do |condition|
t = Time.now.utc
case condition # NB: excludes if condition is false!
when :us_trading_hours
# 09:30 - 16:00 (ET) Mon-Fri 14:30 - 21:00 (UTC)
!(t.wday >= 1 && t.wday <= 5 && t.hour >= 15 && t.hour <= 21)
when :forex_trading_hours
# 17:15 - 17:00 (ET) Sunday-Friday Forex 22:15 - 22:00 (UTC)
!(t.wday > 0 && t.wday < 5 || t.wday == 5 && t.hour < 22)
end
end,

:db => proc { |condition| !IB::DB == condition }, # true/false
:db => proc { |condition| !IB::DB == condition }, # true/false

:reuters => proc { |condition| !OPTS[:connection][:reuters] == condition } # true/false
:reuters => proc { |condition| !OPTS[:connection][:reuters] == condition } # true/false
}
# config.filter = { :focus => true }
# config.include(UserExampleHelpers)
Expand All @@ -62,4 +66,3 @@
end
end
end

0 comments on commit 3073367

Please sign in to comment.