savon_spec 0.1.6 → 1.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.
@@ -0,0 +1,14 @@
1
+ # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
2
+ language: "ruby"
3
+ script: "bundle exec rake"
4
+ rvm:
5
+ - 1.8.7
6
+ - 1.9.2
7
+ - 1.9.3
8
+ - jruby-18mode
9
+ - jruby-19mode
10
+ - rbx-18mode
11
+ - rbx-19mode
12
+ - ree
13
+ notifications:
14
+ irc: "irc.freenode.org#savon"
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source :rubygems
2
2
  gemspec
3
-
4
- gem "autotest"
data/README.md CHANGED
@@ -1,115 +1,150 @@
1
- Savon::Spec
1
+ Savon::Spec [![Build Status](https://secure.travis-ci.org/rubiii/savon_spec.png)](http://travis-ci.org/rubiii/savon_spec)
2
2
  ===========
3
3
 
4
- Savon testing library
4
+ Savon testing library.
5
+
5
6
 
6
7
  Installation
7
8
  ------------
8
9
 
9
10
  Savon::Spec is available through [Rubygems](http://rubygems.org/gems/savon_spec) and can be installed via:
10
11
 
11
- $ gem install savon_spec
12
+ ```
13
+ $ gem install savon_spec
14
+ ```
12
15
 
13
- Dependencies
14
- ------------
15
16
 
16
- Currently, the dependencies are very strict. Savon::Spec is meant to be used with:
17
+ Expects
18
+ -------
19
+
20
+ Include the `Savon::Spec::Macros` module into your specs:
21
+
22
+ ``` ruby
23
+ RSpec.configure do |config|
24
+ config.include Savon::Spec::Macros
25
+ end
26
+ ```
27
+
28
+ By including the module you get a `savon` method to mock SOAP requests. Here's a very simple example:
29
+
30
+ ``` ruby
31
+ let(:client) do
32
+ Savon::Client.new do
33
+ wsdl.endpoint = "http://example.com"
34
+ wsdl.namespace = "http://users.example.com"
35
+ end
36
+ end
37
+
38
+ before do
39
+ savon.expects(:get_user)
40
+ end
41
+
42
+ it "mocks a SOAP request" do
43
+ client.request(:get_user)
44
+ end
45
+ ```
46
+
47
+ This sets up an expectation for Savon to call the `:get_user` action and the specs should pass without errors.
48
+ Savon::Spec does not execute a POST request to your service, but uses [Savon hooks](http://savonrb.com/#hook_into_the_system) to return a fake response:
49
+
50
+ ``` ruby
51
+ { :code => 200, :headers => {}, :body => "" }
52
+ ```
17
53
 
18
- * [Savon](http://rubygems.org/gems/savon) ~> 0.8.0.beta.3
19
- * [RSpec](http://rubygems.org/gems/rspec) ~> 2.0.0
20
- * [Mocha](http://rubygems.org/gems/mocha) ~> 0.9.8
54
+ To further isolate your specs, I'd suggest setting up [FakeWeb](http://rubygems.org/gems/fakeweb) to disallow any HTTP requests.
21
55
 
22
- Note to self: the required versions for RSpec and Mocha could probably be lower.
23
56
 
24
- Getting started
25
- ---------------
57
+ With
58
+ ----
26
59
 
27
- ### Macros
60
+ Mocking SOAP requests is fine, but what you really need to do is verify whether you're sending the right
61
+ parameters to your service.
28
62
 
29
- Include the `Savon::Spec::Macros` module:
63
+ ``` ruby
64
+ before do
65
+ savon.expects(:get_user).with(:id => 1)
66
+ end
30
67
 
31
- RSpec.configure do |config|
32
- config.include Savon::Spec::Macros
33
- end
68
+ it "mocks a SOAP request" do
69
+ client.request(:get_user) do
70
+ soap.body = { :id => 1 }
71
+ end
72
+ end
73
+ ```
34
74
 
35
- ### Mock
75
+ This checks whether Savon uses the SOAP body Hash you expected and raises a `Savon::Spec::ExpectationError` if it doesn't.
36
76
 
37
- By including the macros, you have access to the `savon` method in your specs. It returns a `Savon::Spec::Mock` instance to set up your expectations. It's based on Mocha and comes with similiar methods:
77
+ ```
78
+ Failure/Error: client.request :get_user, :body => { :name => "Dr. Who" }
79
+ Savon::Spec::ExpectationError:
80
+ expected { :id => 1 } to be sent, got: { :name => "Dr. Who" }
81
+ ```
38
82
 
39
- #expects(soap_action) # mocks SOAP request to a given SOAP action
40
- #stubs(soap_action) # stubs SOAP requests to a given SOAP action
41
- #with(soap_body) # expects Savon to send a given SOAP body
42
- #raises_soap_fault # raises or acts like there was a SOAP fault
43
- #returns(response) # returns the given response
83
+ You can also pass a block to the `#with` method and receive the `Savon::SOAP::Request` before the POST request is executed.
84
+ Here's an example of a custom expectation:
44
85
 
45
- ### Fixtures
86
+ ``` ruby
87
+ savon.expects(:get_user).with do |request|
88
+ request.soap.body.should include(:id)
89
+ end
90
+ ```
46
91
 
47
- Savon::Spec works best with SOAP response fixtures (simple XML files) and a conventional folder structure:
48
92
 
49
- ~ spec
50
- ~ fixtures
51
- ~ get_user
52
- - single_user.xml
53
- - multiple_users.xml
54
- + models
55
- + controllers
56
- + helpers
57
- + views
93
+ Returns
94
+ -------
58
95
 
59
- When used inside a Rails 3 application, Savon::Spec uses the command `Rails.root.join("spec", "fixtures")` to locate your fixture directory. In any other case, you have to manually set the fixture path via:
96
+ Instead of the default fake response, you can return a custom HTTP response by passing a Hash to the `#returns` method.
97
+ If you leave out any of these values, Savon::Spec will add the default values for you.
60
98
 
61
- Savon::Spec::Fixture.path = File.expand_path("../fixtures", __FILE__)
99
+ ``` ruby
100
+ savon.expects(:get_user).returns(:code => 500, :headers => {}, :body => "save the unicorns")
101
+ ```
62
102
 
63
- The directories inside the fixture directory should map to SOAP actions and the XML fixtures inside those directories should describe the SOAP response. Please take a look at the following examples to better understand this convention.
103
+ Savon::Spec also works with SOAP response fixtures (simple XML files) and a conventional folder structure:
64
104
 
65
- An example
66
- ----------
105
+ ```
106
+ ~ spec
107
+ ~ fixtures
108
+ ~ get_user
109
+ - single_user.xml
110
+ - multiple_users.xml
111
+ + models
112
+ + controllers
113
+ + helpers
114
+ + views
115
+ ```
67
116
 
68
- user.rb
117
+ When used inside a Rails 3 application, Savon::Spec uses `Rails.root.join("spec", "fixtures")` to locate your fixture directory.
118
+ In any other case, you have to manually set the fixture path via:
69
119
 
70
- class User
120
+ ``` ruby
121
+ Savon::Spec::Fixture.path = File.expand_path("../fixtures", __FILE__)
122
+ ```
71
123
 
72
- def self.all
73
- response = client.request :get_all_users
74
- response.to_hash.map { |user_hash| new user_hash }
75
- end
124
+ Directory names inside the fixtures directory map to SOAP actions and contain actual SOAP responses from your service(s).
125
+ You can use one of those fixtures for the HTTP response body like in the following example:
76
126
 
77
- def self.find(user_id)
78
- response = client.request :get_user do
79
- soap.body = { :id => user_id }
80
- end
81
-
82
- new response.to_hash
83
- end
127
+ ``` ruby
128
+ savon.expects(:get_user).with(:id => 1).returns(:single_user)
129
+ ```
84
130
 
85
- end
131
+ As you can see, Savon::Spec uses the name of your SOAP action and the Symbol passed to the `#returns` method to navigate inside
132
+ your fixtures directory and load the requested XML files.
86
133
 
87
- user_spec.rb
88
134
 
89
- describe User do
135
+ Never
136
+ -----
90
137
 
91
- describe ".all" do
92
- before do
93
- savon.expects(:get_all_users).returns(:multiple_users)
94
- end
138
+ Savon::Spec can also verify that a certain SOAP request was not executed:
95
139
 
96
- it "should return an Array of Users" do
97
- User.all.each { |user| user.should be_a(User) }
98
- end
140
+ ``` ruby
141
+ savon.expects(:get_user).never
142
+ ```
99
143
 
100
- it "should return exactly 7 Users" do
101
- User.all.should have(7).items
102
- end
103
- end
104
144
 
105
- describe ".find" do
106
- before do
107
- savon.expects(:get_user).with(:id => 1).returns(:single_user)
108
- end
145
+ RSpec
146
+ -----
109
147
 
110
- it "should return a User for a given :id" do
111
- User.find(1).should be_a(User)
112
- end
113
- end
148
+ This library is optimized to work with RSpec, but it could be tweaked to work with any other testing library.
149
+ Savon::Spec installs an after filter to clear out its Savon hooks after each example.
114
150
 
115
- end
data/Rakefile CHANGED
@@ -1,39 +1,8 @@
1
- require "rake"
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
3
- begin
4
- require "yard"
5
-
6
- YARD::Rake::YardocTask.new do |t|
7
- t.files = ["README.md", "lib/**/*.rb"]
8
- end
9
- rescue LoadError
10
- desc message = %{"gem install yard" to generate documentation}
11
- task("yard") { abort message }
12
- end
13
-
14
- begin
15
- require "metric_fu"
16
-
17
- MetricFu::Configuration.run do |c|
18
- c.metrics = [:churn, :flog, :flay, :reek, :roodi, :saikuro] # :rcov seems to be broken
19
- c.graphs = [:flog, :flay, :reek, :roodi]
20
- c.flay = { :dirs_to_flay => ["lib"], :minimum_score => 20 }
21
- c.rcov[:rcov_opts] << "-Ilib -Ispec"
22
- end
23
- rescue LoadError
24
- desc message = %{"gem install metric_fu" to generate metrics}
25
- task("metrics:all") { abort message }
26
- end
27
-
28
- begin
29
- require "rspec/core/rake_task"
30
-
31
- RSpec::Core::RakeTask.new do |t|
32
- t.rspec_opts = %w(-fd -c)
33
- end
34
- rescue LoadError
35
- desc message = %{"gem install rspec" to run the specs}
36
- task(:spec) { abort message }
37
- end
4
+ RSpec::Core::RakeTask.new
38
5
 
39
6
  task :default => :spec
7
+ task :test => :spec
8
+
@@ -1,10 +1,16 @@
1
1
  require "savon"
2
2
  require "rspec"
3
- require "mocha"
4
3
 
5
- RSpec.configure do |config|
6
- config.mock_with :mocha
4
+ module Savon
5
+ module Spec
6
+
7
+ autoload :Macros, "savon/spec/macros"
8
+ autoload :Mock, "savon/spec/mock"
9
+ autoload :Fixture, "savon/spec/fixture"
10
+
11
+ end
7
12
  end
8
13
 
9
- require "savon/spec/version"
10
- require "savon/spec/macros"
14
+ RSpec.configure do |config|
15
+ config.after { Savon.config.hooks.reject!(Savon::Spec::Mock::HOOKS) }
16
+ end
@@ -3,13 +3,13 @@ module Savon
3
3
 
4
4
  # = Savon::Spec::Fixture
5
5
  #
6
- # Loads SOAP response fixtures.
6
+ # Manages SOAP response fixtures.
7
7
  class Fixture
8
8
  class << self
9
9
 
10
10
  def path
11
11
  @path ||= Rails.root.join("spec", "fixtures").to_s if defined? Rails
12
-
12
+
13
13
  raise ArgumentError, "Savon::Spec::Fixture.path needs to be specified" unless @path
14
14
  @path
15
15
  end
@@ -18,7 +18,7 @@ module Savon
18
18
 
19
19
  def load(*args)
20
20
  file = args.map { |arg| arg.to_s.snakecase }.join("/")
21
- fixtures[file] ||= load_file file
21
+ fixtures[file] ||= read_file(file)
22
22
  end
23
23
 
24
24
  alias [] load
@@ -29,10 +29,10 @@ module Savon
29
29
  @fixtures ||= {}
30
30
  end
31
31
 
32
- def load_file(file)
32
+ def read_file(file)
33
33
  full_path = File.expand_path File.join(path, "#{file}.xml")
34
34
  raise ArgumentError, "Unable to load: #{full_path}" unless File.exist? full_path
35
-
35
+
36
36
  File.read full_path
37
37
  end
38
38
 
@@ -1,15 +1,13 @@
1
- require "savon/spec/mock"
2
-
3
1
  module Savon
4
2
  module Spec
5
3
 
6
4
  # = Savon::Spec::Macros
7
5
  #
8
- # Include this module into your RSpec tests to mock/stub Savon SOAP requests.
6
+ # Include this module into your RSpec tests to mock Savon SOAP requests.
9
7
  module Macros
10
8
 
11
9
  def savon
12
- Savon::Spec::Mock.new
10
+ Mock.new
13
11
  end
14
12
 
15
13
  end
@@ -1,77 +1,98 @@
1
- require "savon/spec/fixture"
2
-
3
1
  module Savon
4
2
  module Spec
5
3
 
4
+ class ExpectationError < RuntimeError; end
5
+
6
6
  # = Savon::Spec::Mock
7
7
  #
8
- # Mocks/stubs SOAP requests executed by Savon.
8
+ # Mocks Savon SOAP requests.
9
9
  class Mock
10
10
 
11
- # Mocks SOAP requests to a given <tt>soap_action</tt>.
12
- def expects(soap_action)
13
- setup :expects, soap_action
14
- self
15
- end
11
+ # Hooks registered by Savon::Spec.
12
+ HOOKS = [:spec_action, :spec_body, :spec_response, :spec_never]
16
13
 
17
- # Stubs SOAP requests to a given <tt>soap_action</tt>.
18
- def stubs(soap_action)
19
- setup :stubs, soap_action
20
- self
21
- end
14
+ # Expects that a given +action+ should be called.
15
+ def expects(expected)
16
+ self.action = expected
17
+
18
+ Savon.config.hooks.define(:spec_action, :soap_request) do |request|
19
+ actual = request.soap.input[1]
20
+ raise ExpectationError, "expected #{action.inspect} to be called, got: #{actual.inspect}" unless actual == action
21
+
22
+ respond_with
23
+ end
22
24
 
23
- # Expects a given SOAP body Hash to be used.
24
- def with(soap_body)
25
- Savon::SOAP::XML.any_instance.expects(:body=).with(soap_body) if mock_method == :expects
26
25
  self
27
26
  end
28
27
 
29
- def never
30
- httpi_mock.never
28
+ # Accepts a SOAP +body+ to check if it was set. Also accepts a +block+
29
+ # which receives the <tt>Savon::SOAP::Request</tt> to set up custom expectations.
30
+ def with(body = nil, &block)
31
+ Savon.config.hooks.define(:spec_body, :soap_request) do |request|
32
+ if block
33
+ block.call(request)
34
+ else
35
+ actual = request.soap.body
36
+ raise ExpectationError, "expected #{body.inspect} to be sent, got: #{actual.inspect}" unless actual == body
37
+ end
38
+
39
+ respond_with
40
+ end
41
+
31
42
  self
32
43
  end
33
44
 
34
- # Sets up HTTPI to return a given +response+.
45
+ # Expects a given +response+ to be returned.
35
46
  def returns(response = nil)
36
- http = { :code => 200, :headers => {}, :body => "" }
37
-
38
- case response
39
- when Symbol then http[:body] = Fixture[soap_action, response]
40
- when Hash then http.merge! response
41
- when String then http[:body] = response
47
+ http = case response
48
+ when Symbol then { :body => Fixture[action, response] }
49
+ when Hash then response
42
50
  end
43
-
44
- httpi_mock.returns HTTPI::Response.new(http[:code], http[:headers], http[:body])
51
+
52
+ Savon.config.hooks.define(:spec_response, :soap_request) do |request|
53
+ respond_with(http)
54
+ end
55
+
45
56
  self
46
57
  end
47
58
 
48
- # Sets up Savon to respond like there was a SOAP fault.
49
- def raises_soap_fault
50
- Savon::SOAP::Response.any_instance.expects(:soap_fault?).returns(true)
59
+ # Expects that the +action+ doesn't get called.
60
+ def never
61
+ Savon.config.hooks.reject!(:spec_action)
62
+
63
+ Savon.config.hooks.define(:spec_never, :soap_request) do |request|
64
+ actual = request.soap.input[1]
65
+ raise ExpectationError, "expected #{action.inspect} never to be called, but it was!" if actual == action
66
+
67
+ respond_with
68
+ end
69
+
51
70
  self
52
71
  end
53
72
 
54
73
  private
55
74
 
56
- def setup(mock_method, soap_action)
57
- self.mock_method = mock_method
58
- self.soap_action = soap_action
59
- self.httpi_mock = new_httpi_mock
75
+ def action=(action)
76
+ @action = lower_camelcase(action.to_s).to_sym
60
77
  end
61
78
 
62
- attr_accessor :mock_method
79
+ attr_reader :action
63
80
 
64
- def soap_action=(soap_action)
65
- @soap_action = soap_action.kind_of?(Symbol) ? soap_action.to_s.lower_camelcase : soap_action
66
- end
81
+ def respond_with(http = {})
82
+ defaults = { :code => 200, :headers => {}, :body => "" }
83
+ http = defaults.merge(http)
67
84
 
68
- attr_reader :soap_action
69
-
70
- def new_httpi_mock
71
- HTTPI.send(mock_method, :post).with { |http| http.body =~ /<\/(.+:)?#{soap_action}>/ }
85
+ HTTPI::Response.new(http[:code], http[:headers], http[:body])
72
86
  end
73
87
 
74
- attr_accessor :httpi_mock
88
+ # Extracted from CoreExt of Savon 0.9.9
89
+ def lower_camelcase(source_str)
90
+ str = source_str.dup
91
+ str.gsub!(/\/(.?)/) { "::#{$1.upcase}" }
92
+ str.gsub!(/(?:_+|-+)([a-z])/) { $1.upcase }
93
+ str.gsub!(/(\A|\s)([A-Z])/) { $1 + $2.downcase }
94
+ str
95
+ end
75
96
 
76
97
  end
77
98
  end
@@ -1,7 +1,7 @@
1
1
  module Savon
2
2
  module Spec
3
3
 
4
- VERSION = "0.1.6"
4
+ VERSION = "1.1.0"
5
5
 
6
6
  end
7
7
  end
@@ -1 +1,2 @@
1
1
  require "savon/spec"
2
+ require "savon/spec/version"
@@ -1,25 +1,27 @@
1
- lib = File.expand_path("../lib/", __FILE__)
2
- $:.unshift lib unless $:.include?(lib)
3
-
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
4
3
  require "savon/spec/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = "savon_spec"
8
- s.version = Savon::Spec::VERSION
9
- s.authors = "Daniel Harrington"
10
- s.email = "me@rubiii.com"
11
- s.homepage = "http://github.com/rubiii/#{s.name}"
12
- s.summary = "Savon testing library"
13
- s.description = "Test helpers for the Savon SOAP library."
6
+ s.name = "savon_spec"
7
+ s.version = Savon::Spec::VERSION
8
+ s.authors = "Daniel Harrington"
9
+ s.email = "me@rubiii.com"
10
+ s.homepage = "http://github.com/rubiii/#{s.name}"
11
+ s.summary = "Savon testing library"
12
+ s.description = s.summary
14
13
 
15
14
  s.rubyforge_project = s.name
16
15
 
17
- s.add_dependency "savon", ">= 0.8.0"
16
+ s.add_dependency "savon", "~> 0.9.10"
18
17
  s.add_dependency "rspec", ">= 2.0.0"
19
- s.add_dependency "mocha", ">= 0.9.8"
20
18
 
21
19
  s.add_development_dependency "httpclient", "~> 2.1.5"
22
- s.add_development_dependency "webmock", "~> 1.4.0"
20
+ s.add_development_dependency "webmock", "~> 1.4.0"
21
+
22
+ s.add_development_dependency "autotest"
23
+ s.add_development_dependency "rake"
24
+ s.add_development_dependency "ZenTest", "4.5.0"
23
25
 
24
26
  s.files = `git ls-files`.split("\n")
25
27
  s.require_path = "lib"
@@ -2,8 +2,8 @@
2
2
  <soap:Body>
3
3
  <ns2:getUserResponse xmlns:ns2="http://users.example.com/">
4
4
  <return>
5
- <name>Kent</name>
6
- <email>kent@example.com</email>
5
+ <name>Dr. Who</name>
6
+ <email>dr_who@example.com</email>
7
7
  </return>
8
8
  </ns2:getUserResponse>
9
9
  </soap:Body>
@@ -3,43 +3,50 @@ require "spec_helper"
3
3
  describe Savon::Spec::Fixture do
4
4
 
5
5
  describe ".path" do
6
- it "should return a specified path" do
7
- Savon::Spec::Fixture.path = "/Users/rubiii/my_app/spec/fixtures"
8
- Savon::Spec::Fixture.path.should == "/Users/rubiii/my_app/spec/fixtures"
9
-
6
+
7
+ it "returns a specified path" do
8
+ Savon::Spec::Fixture.path = "/Users/dr_who/some_app/spec/fixtures"
9
+ Savon::Spec::Fixture.path.should == "/Users/dr_who/some_app/spec/fixtures"
10
+
10
11
  Savon::Spec::Fixture.path = nil # reset to default
11
12
  end
12
13
 
13
- it "should raise an ArgumentError if accessed before specified" do
14
- lambda { Savon::Spec::Fixture.path }.should raise_error(ArgumentError)
14
+ it "raises an ArgumentError when accessed before specified" do
15
+ expect { Savon::Spec::Fixture.path }.to raise_error(ArgumentError)
15
16
  end
16
17
 
17
- it "should default to spec/fixtures if used in a Rails app" do
18
- Rails = Class.new
19
- Rails.expects(:root).returns(Pathname.new("/Users/rubiii/another_app"))
20
-
21
- Savon::Spec::Fixture.path.should == "/Users/rubiii/another_app/spec/fixtures"
22
-
18
+ it "defaults to spec/fixtures when used in a Rails app" do
19
+ Rails = Class.new do
20
+ def self.root
21
+ Pathname.new("/Users/dr_who/another_app")
22
+ end
23
+ end
24
+
25
+ Savon::Spec::Fixture.path.should == "/Users/dr_who/another_app/spec/fixtures"
26
+
23
27
  Object.send(:remove_const, "Rails")
24
28
  end
29
+
25
30
  end
26
31
 
27
32
  describe ".load" do
33
+
28
34
  around do |example|
29
35
  Savon::Spec::Fixture.path = "spec/fixtures"
30
36
  example.run
31
37
  Savon::Spec::Fixture.path = nil # reset to default
32
38
  end
33
39
 
34
- it "should return a fixture for the given arguments" do
40
+ it "returns a fixture for the given arguments" do
35
41
  fixture = Savon::Spec::Fixture.load :get_user, :success
36
42
  fixture.should == File.read("spec/fixtures/get_user/success.xml")
37
43
  end
38
44
 
39
- it "should memoize the fixtures" do
45
+ it "memoizes the fixtures" do
40
46
  Savon::Spec::Fixture.load(:get_user, :success).
41
47
  should equal(Savon::Spec::Fixture.load(:get_user, :success))
42
48
  end
49
+
43
50
  end
44
51
 
45
52
  end
@@ -4,7 +4,7 @@ describe Savon::Spec::Macros do
4
4
  include Savon::Spec::Macros
5
5
 
6
6
  describe "#savon" do
7
- it "should return a Savon::Spec::Mock instance" do
7
+ it "returns a Savon::Spec::Mock instance" do
8
8
  savon.should be_a(Savon::Spec::Mock)
9
9
  end
10
10
  end
@@ -1,13 +1,9 @@
1
1
  require "spec_helper"
2
2
 
3
- Savon.configure do |config|
4
- config.log = false
5
- end
6
-
7
3
  describe Savon::Spec::Mock do
8
4
  include Savon::Spec::Macros
9
5
 
10
- let :client do
6
+ let(:client) do
11
7
  Savon::Client.new do
12
8
  wsdl.endpoint = "http://example.com"
13
9
  wsdl.namespace = "http://users.example.com"
@@ -15,125 +11,122 @@ describe Savon::Spec::Mock do
15
11
  end
16
12
 
17
13
  describe "#expects" do
18
- before { savon.expects(:get_user).returns }
19
14
 
20
- it "should set up HTTPI to mock POST requests for a given SOAP action" do
21
- client.request :get_user
15
+ before do
16
+ savon.expects(:get_user)
22
17
  end
23
18
 
24
- it "should fail when only parts of the SOAP action matched" do
25
- expect { client.request :get_user_by_id }.to raise_error(
26
- Mocha::ExpectationError,
27
- /expected exactly once, not yet invoked: HTTPI.post/
28
- )
29
-
30
- teardown_mocks_for_rspec
19
+ it "does not execute a POST request (verified via WebMock)" do
20
+ client.request(:get_user)
31
21
  end
32
22
 
33
- it "should fail when no SOAP call was made" do
34
- expect { verify_mocks_for_rspec }.to raise_error(
35
- Mocha::ExpectationError,
36
- /expected exactly once, not yet invoked: HTTPI.post/
23
+ it "fails when a different SOAP action was called" do
24
+ expect { client.request(:get_user_by_id) }.to raise_error(
25
+ Savon::Spec::ExpectationError,
26
+ "expected :getUser to be called, got: :getUserById"
37
27
  )
38
-
39
- teardown_mocks_for_rspec
40
28
  end
29
+
41
30
  end
42
31
 
43
- describe "#expects and #with" do
44
- before { savon.expects(:get_user).with(:id => 1).returns }
32
+ describe "#with" do
33
+
34
+ context "a Hash" do
45
35
 
46
- it "should expect Savon to send a given SOAP body" do
47
- client.request :get_user do
48
- soap.body = { :id => 1 }
36
+ before do
37
+ savon.expects(:get_user).with(:id => 1)
49
38
  end
50
- end
51
39
 
52
- it "should fail when the SOAP body was not send" do
53
- client.request(:get_user)
40
+ it "expects Savon to send a specific SOAP body" do
41
+ client.request :get_user, :body => { :id => 1 }
42
+ end
54
43
 
55
- expect { verify_mocks_for_rspec }.to raise_error(
56
- Mocha::ExpectationError,
57
- /expected exactly once, not yet invoked: #<AnyInstance:Savon::SOAP::XML>.body=\(:id => 1\)/
58
- )
44
+ it "fails when the SOAP body was not set" do
45
+ expect { client.request(:get_user) }.to raise_error(
46
+ Savon::Spec::ExpectationError,
47
+ "expected {:id=>1} to be sent, got: nil"
48
+ )
49
+ end
50
+
51
+ it "fails when the SOAP body did not match the expected value" do
52
+ expect { client.request :get_user, :body => { :id => 2 } }.to raise_error(
53
+ Savon::Spec::ExpectationError,
54
+ "expected {:id=>1} to be sent, got: {:id=>2}"
55
+ )
56
+ end
59
57
 
60
- teardown_mocks_for_rspec
61
58
  end
62
- end
63
59
 
64
- describe "#expects and #never" do
65
- before { savon.expects(:noop).never }
60
+ context "a block" do
66
61
 
67
- it "should not expect Savon to send a given SOAP body" do
68
- expect { client.request(:noop) }.to raise_error(
69
- Mocha::ExpectationError,
70
- /expected never, invoked once: HTTPI.post()/
71
- )
62
+ before do
63
+ savon.expects(:get_user).with do |request|
64
+ request.soap.body.should include(:id)
65
+ end
66
+ end
72
67
 
73
- teardown_mocks_for_rspec
74
- end
75
- end
68
+ it "works with a custom expectation" do
69
+ client.request :get_user, :body => { :id => 1 }
70
+ end
76
71
 
77
- describe "#stubs" do
78
- before { savon.stubs(:get_user).returns }
72
+ it "fails when the expectation was not met" do
73
+ begin
74
+ client.request :get_user, :body => { :name => "Dr. Who" }
75
+ rescue Spec::Expectations::ExpectationNotMetError => e
76
+ e.message.should =~ /expected \{:name=>"Dr. Who"\} to include :id/
77
+ end
78
+ end
79
79
 
80
- it "should set up HTTPI to stub POST requests for a given SOAP action" do
81
- client.request :get_user
82
80
  end
83
81
 
84
- it "should not complain about requests not being executed" do
85
- expect { verify_mocks_for_rspec }.to_not raise_error(Mocha::ExpectationError)
86
- teardown_mocks_for_rspec
87
- end
88
82
  end
89
83
 
90
- describe "#stubs and #with" do
91
- before { savon.stubs(:get_user).with(:id => 1).returns }
84
+ describe "#never" do
92
85
 
93
- it "should not expect Savon to send a given SOAP body" do
94
- client.request :get_user
86
+ before do
87
+ savon.expects(:noop).never
95
88
  end
89
+
90
+ it "expects Savon to never call a specific SOAP action" do
91
+ expect { client.request(:noop) }.to raise_error(
92
+ Savon::Spec::ExpectationError,
93
+ "expected :noop never to be called, but it was!"
94
+ )
95
+ end
96
+
96
97
  end
97
98
 
98
99
  describe "#returns" do
99
- context "without arguments" do
100
- let(:response) { client.request :get_user }
101
-
102
- before { savon.expects(:get_user).returns }
103
100
 
104
- it "should return a response code of 200" do
105
- response.http.code.should == 200
106
- end
101
+ context "without arguments" do
107
102
 
108
- it "should not return any response headers" do
109
- response.http.headers.should == {}
103
+ let(:response) do
104
+ client.request(:get_user)
110
105
  end
111
106
 
112
- it "should return an empty response body" do
113
- response.http.body.should == ""
107
+ before do
108
+ savon.expects(:get_user)
114
109
  end
115
- end
116
110
 
117
- context "with a String" do
118
- let(:response) { client.request :get_user }
119
-
120
- before { savon.expects(:get_user).returns("<soap>response</soap>") }
121
-
122
- it "should return a response code of 200" do
111
+ it "returns a response code of 200" do
123
112
  response.http.code.should == 200
124
113
  end
125
114
 
126
- it "should not return any response headers" do
115
+ it "does not return any response headers" do
127
116
  response.http.headers.should == {}
128
117
  end
129
118
 
130
- it "should return the given response body" do
131
- response.http.body.should == "<soap>response</soap>"
119
+ it "returns an empty response body" do
120
+ response.http.body.should == ""
132
121
  end
122
+
133
123
  end
134
124
 
135
125
  context "with a Symbol" do
136
- let(:response) { client.request :get_user }
126
+
127
+ let(:response) do
128
+ client.request(:get_user)
129
+ end
137
130
 
138
131
  around do |example|
139
132
  Savon::Spec::Fixture.path = "spec/fixtures"
@@ -144,56 +137,48 @@ describe Savon::Spec::Mock do
144
137
  Savon::Spec::Fixture.path = nil # reset to default
145
138
  end
146
139
 
147
- it "should return a response code of 200" do
140
+ it "returns a response code of 200" do
148
141
  response.http.code.should == 200
149
142
  end
150
143
 
151
- it "should not return any response headers" do
144
+ it "does not return any response headers" do
152
145
  response.http.headers.should == {}
153
146
  end
154
147
 
155
- it "should return the :success fixture for the :get_user action" do
148
+ it "returns the :success fixture for the :get_user action" do
156
149
  response.http.body.should == File.read("spec/fixtures/get_user/success.xml")
157
150
  end
151
+
158
152
  end
159
153
 
160
154
  context "with a Hash" do
161
- let(:response) { client.request :get_user }
162
155
 
163
- before do
164
- @hash = { :code => 201, :headers => { "Set-Cookie" => "ID=1; Max-Age=3600;" }, :body => "<with>cookie</with>" }
165
- savon.expects(:get_user).returns(@hash)
156
+ let(:response) do
157
+ client.request(:get_user)
166
158
  end
167
159
 
168
- it "should return the given response code" do
169
- response.http.code.should == @hash[:code]
160
+ let(:http) do
161
+ { :code => 201, :headers => { "Set-Cookie" => "ID=1; Max-Age=3600;" }, :body => "<with>cookie</with>" }
170
162
  end
171
163
 
172
- it "should return the given response headers" do
173
- response.http.headers.should == @hash[:headers]
164
+ before do
165
+ savon.expects(:get_user).returns(http)
174
166
  end
175
167
 
176
- it "should return the given response body" do
177
- response.http.body.should == @hash[:body]
168
+ it "returns the given response code" do
169
+ response.http.code.should == http[:code]
178
170
  end
179
- end
180
- end
181
-
182
- describe "#with_soap_fault" do
183
- before { savon.expects(:get_user).raises_soap_fault.returns }
184
-
185
- it "should raise a SOAP fault" do
186
- expect { client.request :get_user }.to raise_error(Savon::SOAP::Fault)
187
- end
188
171
 
189
- it "should just act like there was a SOAP fault if raising errors was disabled" do
190
- Savon.raise_errors = false
172
+ it "returns the given response headers" do
173
+ response.http.headers.should == http[:headers]
174
+ end
191
175
 
192
- response = client.request :get_user
193
- response.should be_a_soap_fault
176
+ it "returns the given response body" do
177
+ response.http.body.should == http[:body]
178
+ end
194
179
 
195
- Savon.raise_errors = true # reset to default
196
180
  end
181
+
197
182
  end
198
183
 
199
184
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: savon_spec
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
- - 0
8
7
  - 1
9
- - 6
10
- version: 0.1.6
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Harrington
@@ -15,29 +15,26 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-03 00:00:00 +02:00
19
- default_executable:
18
+ date: 2012-06-06 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- name: savon
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
22
  none: false
26
23
  requirements:
27
- - - ">="
24
+ - - ~>
28
25
  - !ruby/object:Gem::Version
29
- hash: 63
26
+ hash: 47
30
27
  segments:
31
28
  - 0
32
- - 8
33
- - 0
34
- version: 0.8.0
29
+ - 9
30
+ - 10
31
+ version: 0.9.10
32
+ name: savon
35
33
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
34
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
38
  none: false
42
39
  requirements:
43
40
  - - ">="
@@ -48,28 +45,12 @@ dependencies:
48
45
  - 0
49
46
  - 0
50
47
  version: 2.0.0
48
+ name: rspec
51
49
  type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: mocha
55
50
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 43
62
- segments:
63
- - 0
64
- - 9
65
- - 8
66
- version: 0.9.8
67
- type: :runtime
68
- version_requirements: *id003
51
+ requirement: *id002
69
52
  - !ruby/object:Gem::Dependency
70
- name: httpclient
71
- prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
73
54
  none: false
74
55
  requirements:
75
56
  - - ~>
@@ -80,12 +61,12 @@ dependencies:
80
61
  - 1
81
62
  - 5
82
63
  version: 2.1.5
64
+ name: httpclient
83
65
  type: :development
84
- version_requirements: *id004
85
- - !ruby/object:Gem::Dependency
86
- name: webmock
87
66
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
67
+ requirement: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
89
70
  none: false
90
71
  requirements:
91
72
  - - ~>
@@ -96,9 +77,55 @@ dependencies:
96
77
  - 4
97
78
  - 0
98
79
  version: 1.4.0
80
+ name: webmock
99
81
  type: :development
100
- version_requirements: *id005
101
- description: Test helpers for the Savon SOAP library.
82
+ prerelease: false
83
+ requirement: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ name: autotest
95
+ type: :development
96
+ prerelease: false
97
+ requirement: *id005
98
+ - !ruby/object:Gem::Dependency
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ name: rake
109
+ type: :development
110
+ prerelease: false
111
+ requirement: *id006
112
+ - !ruby/object:Gem::Dependency
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - "="
117
+ - !ruby/object:Gem::Version
118
+ hash: 43
119
+ segments:
120
+ - 4
121
+ - 5
122
+ - 0
123
+ version: 4.5.0
124
+ name: ZenTest
125
+ type: :development
126
+ prerelease: false
127
+ requirement: *id007
128
+ description: Savon testing library
102
129
  email: me@rubiii.com
103
130
  executables: []
104
131
 
@@ -109,6 +136,7 @@ extra_rdoc_files: []
109
136
  files:
110
137
  - .gitignore
111
138
  - .rspec
139
+ - .travis.yml
112
140
  - Gemfile
113
141
  - README.md
114
142
  - Rakefile
@@ -124,7 +152,6 @@ files:
124
152
  - spec/savon/spec/macros_spec.rb
125
153
  - spec/savon/spec/mock_spec.rb
126
154
  - spec/spec_helper.rb
127
- has_rdoc: true
128
155
  homepage: http://github.com/rubiii/savon_spec
129
156
  licenses: []
130
157
 
@@ -154,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
181
  requirements: []
155
182
 
156
183
  rubyforge_project: savon_spec
157
- rubygems_version: 1.4.1
184
+ rubygems_version: 1.8.21
158
185
  signing_key:
159
186
  specification_version: 3
160
187
  summary: Savon testing library