fix_spec 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -114,7 +114,7 @@ FIXSpec works best when a DataDictionary is provided. With a DataDictionary loa
114
114
  The DataDictionary is globally set:
115
115
 
116
116
  ```ruby
117
- FIXSpec::data_dictionary = quickfix.DataDictionary.new "config/FIX42.xml"
117
+ FIXSpec::data_dictionary = FIXSpec::DataDictionary.new "config/FIX42.xml"
118
118
  ```
119
119
 
120
120
  #### Exclusion
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -8,7 +8,7 @@ def last_fix
8
8
  end
9
9
 
10
10
  Around('@with_data_dictionary') do |scenario, block|
11
- FIXSpec::data_dictionary= quickfix.DataDictionary.new "features/support/FIX42.xml"
11
+ FIXSpec::data_dictionary= FIXSpec::DataDictionary.new "features/support/FIX42.xml"
12
12
  block.call
13
13
  FIXSpec::data_dictionary= nil
14
14
  end
data/fix_spec.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fix_spec"
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Busbey"]
12
- s.date = "2013-08-30"
12
+ s.date = "2013-10-22"
13
13
  s.description = "Build and Inspect FIX Messages with RSpec and Cucumber steps"
14
14
  s.email = "info@connamara.com"
15
15
  s.extra_rdoc_files = [
@@ -43,10 +43,12 @@ Gem::Specification.new do |s|
43
43
  "lib/fix_spec/builder.rb",
44
44
  "lib/fix_spec/configuration.rb",
45
45
  "lib/fix_spec/cucumber.rb",
46
+ "lib/fix_spec/data_dictionary.rb",
46
47
  "lib/fix_spec/helpers.rb",
47
48
  "lib/fix_spec/matchers.rb",
48
49
  "lib/fix_spec/matchers/be_fix_eql.rb",
49
50
  "lib/fix_spec/matchers/have_fix_path.rb",
51
+ "spec/data_dictionary_spec.rb",
50
52
  "spec/fix_spec/helpers_spec.rb",
51
53
  "spec/spec_helper.rb"
52
54
  ]
@@ -73,11 +73,6 @@ Given /^I set the (?:FIX|fix) message at(?: tag)? "(.*?)" to (".*"|\-?\d+(?:\.\d
73
73
  msg = msg.get_trailer
74
74
  end
75
75
 
76
- if tag == -1 then
77
- msg.setString(fieldName, fieldValue)
78
- return
79
- end
80
-
81
76
  case FIXSpec::data_dictionary.get_field_type_enum(tag).get_name
82
77
  when "INT","DAYOFMONTH" then
83
78
  msg.setInt(tag, fieldValue.to_i)
@@ -86,6 +81,9 @@ Given /^I set the (?:FIX|fix) message at(?: tag)? "(.*?)" to (".*"|\-?\d+(?:\.\d
86
81
  when "BOOLEAN" then
87
82
  msg.setBoolean(tag, fieldValue == "true")
88
83
  else
84
+ #enum description => enum value
85
+ #e.g. tag 54 "BUY"=>"1"
86
+ fieldValue = FIXSpec::data_dictionary.get_reverse_value_name(tag, fieldValue)
89
87
  msg.setString(tag, fieldValue)
90
88
  end
91
89
 
@@ -0,0 +1,41 @@
1
+ #encoding ascii
2
+
3
+ require 'rexml/document'
4
+
5
+ module FIXSpec
6
+ class DataDictionary < quickfix.DataDictionary
7
+
8
+ def initialize fileName
9
+ super fileName
10
+ @reverse_lookup = Hash.new({})
11
+
12
+ parse_xml(fileName)
13
+ end
14
+
15
+ def get_reverse_value_name(tag, name)
16
+ if(@reverse_lookup[tag].has_key?(name))
17
+ @reverse_lookup[tag][name]
18
+ else
19
+ name
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def parse_xml fileName
26
+ doc = REXML::Document.new File.new(fileName)
27
+ doc.elements.each("fix/fields/field") do |f|
28
+ tag = f.attributes['number'].to_i
29
+
30
+ f.elements.each("value") do |v|
31
+ @reverse_lookup[ tag ][v.attributes['description'] ] = v.attributes['enum']
32
+ end
33
+ end
34
+
35
+ #also map pretty msg type names
36
+ doc.elements.each("fix/messages/message") do |m|
37
+ @reverse_lookup[35][m.attributes['name']] = m.attributes['msgtype']
38
+ end
39
+ end
40
+ end
41
+ end
data/lib/fix_spec.rb CHANGED
@@ -4,6 +4,7 @@ require 'json_spec'
4
4
  require 'fix_spec/configuration'
5
5
  require 'fix_spec/helpers'
6
6
  require 'fix_spec/matchers'
7
+ require 'fix_spec/data_dictionary'
7
8
 
8
9
  module FIXSpec
9
10
  extend Configuration
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe FIXSpec::DataDictionary do
4
+ let(:dict) {FIXSpec::DataDictionary.new "features/support/FIX42.xml" }
5
+
6
+ it "is a quickfix.DataDictionary" do
7
+ dict.is_a?(quickfix.DataDictionary).should be_true
8
+ end
9
+
10
+ describe "get_reverse_value_name" do
11
+ it "gives me back the same if not an enum" do
12
+ dict.get_reverse_value_name(1, 'Ralph').should ==('Ralph')
13
+ end
14
+
15
+ it "knows enum lookup" do
16
+ dict.get_reverse_value_name(54, 'BUY').should ==('1')
17
+ end
18
+
19
+ it "knows how to map msg type" do
20
+ dict.get_reverse_value_name(35, 'NewOrderSingle').should ==('D')
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: fix_spec
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris Busbey
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-30 00:00:00.000000000 Z
12
+ date: 2013-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_spec
@@ -157,10 +157,12 @@ files:
157
157
  - lib/fix_spec/builder.rb
158
158
  - lib/fix_spec/configuration.rb
159
159
  - lib/fix_spec/cucumber.rb
160
+ - lib/fix_spec/data_dictionary.rb
160
161
  - lib/fix_spec/helpers.rb
161
162
  - lib/fix_spec/matchers.rb
162
163
  - lib/fix_spec/matchers/be_fix_eql.rb
163
164
  - lib/fix_spec/matchers/have_fix_path.rb
165
+ - spec/data_dictionary_spec.rb
164
166
  - spec/fix_spec/helpers_spec.rb
165
167
  - spec/spec_helper.rb
166
168
  homepage: http://github.com/connamara/fix_spec