api_matchers 0.0.2 → 0.1.0

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/History.markdown CHANGED
@@ -1,3 +1,11 @@
1
+ ## v0.1.0
2
+
3
+ 1) Add the #including_text for have_json_node and have_xml_node matcher:
4
+
5
+ { :error => "Transaction error: Name can't be blank" }.to_json.should have_json_node(:error).including_text("Transaction error")
6
+
7
+ "<error>Transaction error: Name can't be blank</error>".should have_xml_node(:error).including_text("Transaction error")
8
+
1
9
  ## v0.0.2
2
10
 
3
11
  1) Put the headers method and the content type key in the setup class and that will be used by the headers matchers(be_json and be_xml).
data/api_matchers.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = APIMatchers::VERSION
17
17
 
18
- gem.add_dependency 'rspec', '>= 2.11.0'
19
- gem.add_dependency 'activesupport', '>= 3.2.6'
20
- gem.add_dependency 'nokogiri', '>= 1.5.5'
18
+ gem.add_dependency 'rspec', '>= 2.10.0'
19
+ gem.add_dependency 'activesupport', '>= 3.2.5'
20
+ gem.add_dependency 'nokogiri', '>= 1.5.2'
21
21
  end
@@ -18,6 +18,11 @@ module APIMatchers
18
18
  self
19
19
  end
20
20
 
21
+ def including_text(expected_including_text)
22
+ @expected_including_text = expected_including_text
23
+ self
24
+ end
25
+
21
26
  def response_body
22
27
  if @setup.response_body_method.present?
23
28
  @actual.send(@setup.response_body_method)
@@ -37,6 +42,8 @@ module APIMatchers
37
42
  def added_message
38
43
  if @with_value
39
44
  " with value: '#{@with_value}'"
45
+ elsif @expected_including_text
46
+ " including text: '#{@expected_including_text}'"
40
47
  else
41
48
  ""
42
49
  end
@@ -16,6 +16,8 @@ module APIMatchers
16
16
 
17
17
  if @with_value
18
18
  node.to_s == @with_value.to_s
19
+ elsif @expected_including_text
20
+ node.to_s.include?(@expected_including_text)
19
21
  else
20
22
  node.present?
21
23
  end
@@ -10,6 +10,8 @@ module APIMatchers
10
10
 
11
11
  if @with_value
12
12
  node == @with_value.to_s
13
+ elsif @expected_including_text
14
+ node.to_s.include?(@expected_including_text)
13
15
  else
14
16
  node.present?
15
17
  end
@@ -1,3 +1,3 @@
1
1
  module APIMatchers
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -51,6 +51,18 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
51
51
  }.to fail_with(%Q{expected to have node called: 'code' with value: '001'. Got: '{"transaction":{"id":150,"error":{"code":"999"}}}'})
52
52
  end
53
53
  end
54
+
55
+ context "including_text" do
56
+ it "should pass when the expected is included in the actual" do
57
+ { :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should have_json_node(:message).including_text("Transaction error")
58
+ end
59
+
60
+ it "should fail when the expected is not included in the actual" do
61
+ expect {
62
+ { :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should have_json_node(:message).including_text("Fox on the run")
63
+ }.to fail_with(%Q{expected to have node called: 'message' including text: 'Fox on the run'. Got: '{"transaction":{"error":{"message":"Transaction error: Name can't be blank"}}}'})
64
+ end
65
+ end
54
66
  end
55
67
 
56
68
  describe "actual.should_not have_json_node" do
@@ -77,6 +89,18 @@ describe APIMatchers::ResponseBody::HaveJsonNode do
77
89
  { :status => 'paid' }.to_json.should_not have_json_node(:status).with('paid')
78
90
  }.to fail_with(%Q{expected to NOT have node called: 'status' with value: 'paid'. Got: '{"status":"paid"}'})
79
91
  end
92
+
93
+ context "including_text" do
94
+ it "should pass when the expected is NOT included in the actual" do
95
+ { :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should_not have_json_node(:message).including_text("Love gun")
96
+ end
97
+
98
+ it "should fail when the expected is included in the actual" do
99
+ expect {
100
+ { :transaction => { :error => { :message => "Transaction error: Name can't be blank" } } }.to_json.should_not have_json_node(:message).including_text("Transaction error")
101
+ }.to fail_with(%Q{expected to NOT have node called: 'message' including text: 'Transaction error'. Got: '{"transaction":{"error":{"message":"Transaction error: Name can't be blank"}}}'})
102
+ end
103
+ end
80
104
  end
81
105
 
82
106
  describe "with change configuration" do
@@ -51,6 +51,18 @@ describe APIMatchers::ResponseBody::HaveXmlNode do
51
51
  }.to fail_with(%Q{expected to have node called: 'code' with value: '001'. Got: '<transaction><error><code>999</code></error></transaction>'})
52
52
  end
53
53
  end
54
+
55
+ context "including_text" do
56
+ it "should pass when the expected is included in the actual" do
57
+ "<error><message>Transaction error: Name can't be blank</message></error>".should have_xml_node(:message).including_text("Transaction error")
58
+ end
59
+
60
+ it "should fail when the expected is not included in the actual" do
61
+ expect {
62
+ "<error><message>Transaction error: Name can't be blank</message></error>".should have_xml_node(:message).including_text("Fox on the run")
63
+ }.to fail_with(%Q{expected to have node called: 'message' including text: 'Fox on the run'. Got: '<error><message>Transaction error: Name can't be blank</message></error>'})
64
+ end
65
+ end
54
66
  end
55
67
 
56
68
  describe "actual.should_not have_xml_node" do
@@ -77,6 +89,18 @@ describe APIMatchers::ResponseBody::HaveXmlNode do
77
89
  "<transaction><status>paid</status></transaction>".should_not have_xml_node(:status).with('paid')
78
90
  }.to fail_with(%Q{expected to NOT have node called: 'status' with value: 'paid'. Got: '<transaction><status>paid</status></transaction>'})
79
91
  end
92
+
93
+ context "including_text" do
94
+ it "should pass when the expected is included in the actual" do
95
+ "<error><message>Transaction error: Name can't be blank</message></error>".should_not have_xml_node(:message).including_text("Girls of Summer")
96
+ end
97
+
98
+ it "should fail when the expected is not included in the actual" do
99
+ expect {
100
+ "<error><message>Transaction error: Name can't be blank</message></error>".should_not have_xml_node(:message).including_text("Transaction error")
101
+ }.to fail_with(%Q{expected to NOT have node called: 'message' including text: 'Transaction error'. Got: '<error><message>Transaction error: Name can't be blank</message></error>'})
102
+ end
103
+ end
80
104
  end
81
105
 
82
106
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,41 +9,41 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-31 00:00:00.000000000Z
12
+ date: 2012-08-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2156860320 !ruby/object:Gem::Requirement
16
+ requirement: &2160643300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.11.0
21
+ version: 2.10.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156860320
24
+ version_requirements: *2160643300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2156859820 !ruby/object:Gem::Requirement
27
+ requirement: &2160642800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 3.2.6
32
+ version: 3.2.5
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156859820
35
+ version_requirements: *2160642800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &2156859360 !ruby/object:Gem::Requirement
38
+ requirement: &2160642340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
- version: 1.5.5
43
+ version: 1.5.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2156859360
46
+ version_requirements: *2160642340
47
47
  description: Collection of RSpec matchers for create your API.
48
48
  email:
49
49
  - tomas_stefano@successoft.com