README.md in webmock_method-1.0.0 vs README.md in webmock_method-1.0.1
- old
+ new
@@ -100,9 +100,37 @@
webmock_method :purchase, [:amount, :credit_card], lambda { |binding|
RenderHelper.render :xml, "#{File.dirname(__FILE__)}/templates/purchase_response.xml.erb", binding
}
```
+You can tweak you response on the fly:
+
+```ruby
+ webmock_method :purchase, [:amount, :credit_card], lambda { |binding|
+ RenderHelper.render :xml, "#{File.dirname(__FILE__)}/templates/purchase_response.xml.erb", binding
+ } do |parent, _, credit_card|
+ if credit_card.card_type == "VISA"
+ define_attribute(parent, :success, true)
+ else
+ define_attribute(parent, :success, false)
+ define_attribute(parent, :error_message, "Unsupported Credit Card Type")
+ end
+ end
+```
+
+and then, use new defined attributes, such as **success** and **error_message** inside your template:
+
+```xml
+<!-- stubs/templates/purchase_response.xml.erb -->
+<PurchaseResponse>
+ <Success><%= success %></Success>
+
+ <% unless success %>
+ <ErrorMessage><%= error_message %></ErrorMessage>
+ <% end %>
+</PurchaseResponse>
+```
+
**url** parameter is optional. If you don't specify it, it will try to use **url** attribute defined
on your service or you can define **url** parameter for WebmockMethod:
```ruby
WebmockMethod.url = "http://api.openweathermap.org/data/2.5/weather"