Project

fix_spec

0.02
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Build and Inspect FIX Messages with RSpec and Cucumber steps
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 1.8
>= 0
~> 10.1
~> 2.14

Runtime

~> 0.1.1
~> 1.1.1
>= 1.6.4, ~> 1.6
 Project Readme

fix_spec Build Status

RSpec matchers and Cucumber step definitions for testing FIX Messages using json_spec and quickfix-jruby

Usage

RSpec

fix_spec currently defines two matchers:

  • be_fix_eql
  • have_fix_path

The matchers can be used as their counterparts are used in json_spec

Cucumber

fix_spec provides Cucumber steps that utilize its RSpec matchers.

In order to us ethe Cucumber steps, in your env.rb you must:

require "fix_spec"
require "fix_spec/cucumber"

"Should" Assertions

In order to test the contents of a FIX message, you will need to define a last_fix method. This method will be called by fix_spec to grab the FIX message to test. For example, suppose a step aquires a fix message and assigns it to @my_fix_message. In your env.rb you could then have

def last_fix
  @my_fix_message
end

See features/support/env.rb and features/step_definitions/steps.rb for a very simple implementation.

Now you can use fix_spec steps in your features:

Feature: New Order

Background:

Given some order message

Scenario: A Market Order is valid
Then the FIX message type should be "NewOrderSingle"
Then the FIX should have tag "OrderQty"
And the FIX message should not have tag "Price"
And the FIX at "SenderCompID" should be "MY_SENDER"

And the FIX messsage should have the following:
|SenderCompID | "MY_SENDER" |
|TargetCompID | "MY_TARGET" |
|OrderQty     | 123         |
|OrdType      | "MARKET"    |

And the FIX message should be:
"""
{
  "BeginString":"FIX.4.2",
  "BodyLength":81,
  "MsgType":"NewOrderSingle",
  "SenderCompID":"MY_SENDER",
  "TargetCompID":"MY_TARGET",
  "OrdType": "MARKET",
  "OrderQty": 123,
  "CheckSum":"083"
}
"""

And the FIX message should be:
"""
8=FIX.4.2�9-81�35=D�49=MY_SENDER�56=MY_TARGET�40=1�38=123�10=083�
"""

The background step isn't provided by fix_spec. The remaining steps fix_spec provides. See features for more examples.

Building FIX Messages

You can build FIX Message messages in your features:

Feature: Order Adapter accepts Orders

Scenario: It accepts Market Orders

Given I create a FIX.4.2 message of type "NewOrderSingle"
And I set the FIX message at "SenderCompID" to "MY_SENDER"
And I set the FIX message at "TargetCompID" to "MY_TARGET"
And I set the FIX message at "OrdType" to "MARKET"
And I set the FIX message at "OrderQty" to 123
Then I send the message

Or it can be simplified using a table:

Given I create the following FIX.4.2 message of type "NewOrderSingle":
| SenderCompID | "MY_SENDER" |
| TargetCompID | "MY_TARGET" |
| OrdType      | "MARKET"    |
| OrderQty     | 123         |

You can even do repeating groups:

Given I create the following FIX.4.2 message of type "NewOrderList":
| ListID      | "List_ID" |
And I add the following "NoOrders" group:
| Symbol   | "ABC" |
| Side     | "BUY" |
| OrderQty | 123   |
And I add the following "NoOrders" group:
| Symbol   | "ABC"  |
| Side     | "SELL" |
| OrderQty | 123    |

The built FIX message can be accessed through the message function in the FIXSpec::Builder module.

Configuration

DataDictionary

FIXSpec works best when a DataDictionary is provided. With a DataDictionary loaded, you can inspect a message with named tags, enumeration, and type specific tag values.

The DataDictionary is globally set:

FIXSpec.data_dictionary = FIXSpec::DataDictionary.new "config/FIX42.xml"

Exclusion

When checking for fix message equality, you may wish to ignore some common fields that are mostly session level. For example, at an application level, BodyLength and CheckSum can be assumed to be set correctly. Tag exclusion is configured globally via JsonSpec:

JsonSpec.configure do
  exclude_keys "BodyLength", "CheckSum", "MsgSeqNum"
end

More

Check out specs and features to see all the ways you can use fix_spec.

Install

gem install fix_spec

or add the following to Gemfile:

gem 'fix_spec'

and run bundle install from your shell.

More Information

Contributing

Please see the contribution guidelines.

Credits

Contributers:

Connamara Systems

fix_spec is maintained and funded by Connamara Systems, llc.

The names and logos for Connamara Systems are trademarks of Connamara Systems, llc.

Licensing

fix_spec is Copyright © 2016 Connamara Systems, llc.

This software is available under the GPL and a commercial license. Please see the LICENSE file for the terms specified by the GPL license. The commercial license offers more flexible licensing terms compared to the GPL, and includes support services. Contact us for more information on the Connamara commercial license, what it enables, and how you can start commercial development with it.

This product includes software developed by quickfixengine.org (http://www.quickfixengine.org/). Please see the QuickFIX Software LICENSE for the terms specified by the QuickFIX Software License.