Permalink
Browse files

Reponse.mock is setable through options.

  • Loading branch information...
1 parent ac8af85 commit 619d7b45e53d504bd8c2d4806a14c96f898d5c00 @i0rek i0rek committed Oct 2, 2012
Showing with 33 additions and 1 deletion.
  1. +6 −1 lib/typhoeus/response.rb
  2. +27 −0 spec/typhoeus/response_spec.rb
@@ -27,7 +27,7 @@ class Response
attr_accessor :options
# @api private
- attr_accessor :mock
+ attr_writer :mock
# Create a new response.
#
@@ -41,5 +41,10 @@ def initialize(options = {})
@options = options
@headers = options[:headers]
end
+
+ # @api private
+ def mock
+ defined?(@mock) ? @mock : options[:mock]
+ end
end
end
@@ -13,4 +13,31 @@
end
end
end
+
+ describe "#mock" do
+ context "when @mock" do
+ before { response.mock = true }
+
+ it "returns @mock" do
+ expect(response.mock).to be_true
+ end
+ end
+
+ context "when options[:mock]" do
+ let(:options) { {:mock => true} }
+
+ it "returns options[:mock]" do
+ expect(response.mock).to be_true
+ end
+ end
+
+ context "when @mock and options[:mock]" do
+ let(:options) { {:mock => 1} }
+ before { response.mock = 2 }
+
+ it "returns @mock" do
+ expect(response.mock).to be(2)
+ end
+ end
+ end
end

0 comments on commit 619d7b4

Please sign in to comment.