dozuki-mapper 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .rvmrc
6
+ tmp/*
data/README.markdown CHANGED
@@ -97,6 +97,11 @@ Example:
97
97
  * [Mapping each](https://github.com/jamesalmond/dozuki-mapper/tree/master/features/each_mapping.feature)
98
98
 
99
99
 
100
+ ## Testing your matchers
101
+
102
+ * [with RSpec](https://github.com/jamesalmond/dozuki-mapper/tree/master/features/rspec_matchers.feature)
103
+
104
+
100
105
  ## Contributing to Dozuki Mapper
101
106
 
102
107
  * Fork the project.
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.add_development_dependency("rspec")
25
25
  s.add_development_dependency("cucumber")
26
+ s.add_development_dependency("aruba")
26
27
  s.add_development_dependency("autotest")
27
28
  s.add_development_dependency("rake")
28
29
  end
@@ -0,0 +1,69 @@
1
+ Feature: Spec matchers
2
+ So that I can write simple tests against my mapper
3
+ As a test driven developer
4
+ I want to test my mappings using RSpec
5
+
6
+
7
+ @matchers
8
+ Scenario: a simple string matcher
9
+ Given a file named "matchers/string_spec.rb" with:
10
+ """
11
+ require 'rspec'
12
+ require 'dozuki-mapper'
13
+ require 'dozuki-mapper/rspec/matchers'
14
+
15
+ class Person
16
+ include Dozuki::Mapper
17
+ map_with do |mapper|
18
+ mapper.string :name
19
+ mapper.date :dob
20
+ mapper.boolean :male
21
+ mapper.int :age
22
+ mapper.float :bank_balance
23
+ mapper.node :address, :as => Address
24
+ mapper.each :child, :as => Person, :to => :children
25
+ end
26
+ end
27
+
28
+ class Address; end
29
+
30
+ describe Person do
31
+ describe "mappings" do
32
+ subject { Person }
33
+ it { should map(:name).to_a(:string) }
34
+ it { should map(:dob).to_a(:date) }
35
+ it { should map(:male).to_a(:boolean) }
36
+ it { should map(:age).to_an(:int) }
37
+ it { should map(:bank_balance).to_a(:float) }
38
+ it { should map(:address).to_a(:node).as(Address)}
39
+ it { should map(:child).to_an(:each).as(Person).to(:children)}
40
+ end
41
+ end
42
+ """
43
+ When I run `rspec matchers/string_spec.rb`
44
+ Then the output should contain "7 examples, 0 failures"
45
+
46
+ @matchers
47
+ Scenario: a simple string matcher, that fails
48
+ Given a file named "matchers/failing_string_spec.rb" with:
49
+ """
50
+ require 'rspec'
51
+ require 'dozuki-mapper'
52
+ require 'dozuki-mapper/rspec/matchers'
53
+
54
+ class Shop
55
+ include Dozuki::Mapper
56
+ map_with do |mapper|
57
+ mapper.string :name
58
+ end
59
+ end
60
+
61
+ describe Shop do
62
+ describe "mappings" do
63
+ subject { Shop }
64
+ it { should map(:giant).to_a(:string) }
65
+ end
66
+ end
67
+ """
68
+ When I run `rspec matchers/failing_string_spec.rb`
69
+ Then the output should contain "1 example, 1 failure"
@@ -1 +1,2 @@
1
1
  require 'dozuki-mapper'
2
+ require 'aruba/cucumber'
@@ -0,0 +1,35 @@
1
+ RSpec::Matchers.define :map do |field|
2
+ chain :to_a do |type|
3
+ @type = type
4
+ end
5
+ chain :to_an do |type|
6
+ @type = type
7
+ end
8
+ chain :to do |to|
9
+ @to = to
10
+ end
11
+ chain :as do |as|
12
+ @as = as
13
+ end
14
+ match do |klass|
15
+ @field = field
16
+ proxy = mock(:proxy).as_null_object
17
+ case @type
18
+ when :node
19
+ matcher = proxy.should_receive(:node)
20
+ matcher.with(field, :as => @as)
21
+ when :each
22
+ matcher = proxy.should_receive(:each)
23
+ matcher.with(field, :to => @to, :as => @as)
24
+ else
25
+ matcher = proxy.should_receive(@type)
26
+ matcher.with field
27
+ end
28
+ klass.mapper.call proxy
29
+ matcher.expected_messages_received?
30
+ end
31
+
32
+ failure_message_for_should do |model|
33
+ "Expected #{model.name} to map #{@field} as a #{@type}"
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  module Dozuki
2
2
  module Mapper
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dozuki-mapper
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Almond
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-16 00:00:00 +01:00
13
+ date: 2011-05-18 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -47,7 +47,7 @@ dependencies:
47
47
  type: :development
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
50
- name: autotest
50
+ name: aruba
51
51
  prerelease: false
52
52
  requirement: &id004 !ruby/object:Gem::Requirement
53
53
  none: false
@@ -58,7 +58,7 @@ dependencies:
58
58
  type: :development
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
61
- name: rake
61
+ name: autotest
62
62
  prerelease: false
63
63
  requirement: &id005 !ruby/object:Gem::Requirement
64
64
  none: false
@@ -68,6 +68,17 @@ dependencies:
68
68
  version: "0"
69
69
  type: :development
70
70
  version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: rake
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id006
71
82
  description: A DSL for mapping API output to objects
72
83
  email:
73
84
  - james@jamesalmond.com
@@ -91,6 +102,7 @@ files:
91
102
  - features/float_mapping.feature
92
103
  - features/int_mapping.feature
93
104
  - features/node_mapping.feature
105
+ - features/rspec_matchers.feature
94
106
  - features/step_definitions/boolean_steps.rb
95
107
  - features/step_definitions/date_steps.rb
96
108
  - features/step_definitions/each_steps.rb
@@ -102,6 +114,7 @@ files:
102
114
  - features/support/env.rb
103
115
  - lib/dozuki-mapper.rb
104
116
  - lib/dozuki-mapper/proxy.rb
117
+ - lib/dozuki-mapper/rspec/matchers.rb
105
118
  - lib/dozuki-mapper/version.rb
106
119
  - spec/dozuki-mapper/proxy_spec.rb
107
120
  - spec/dozuki-mapper_spec.rb
@@ -142,6 +155,7 @@ test_files:
142
155
  - features/float_mapping.feature
143
156
  - features/int_mapping.feature
144
157
  - features/node_mapping.feature
158
+ - features/rspec_matchers.feature
145
159
  - features/step_definitions/boolean_steps.rb
146
160
  - features/step_definitions/date_steps.rb
147
161
  - features/step_definitions/each_steps.rb