Skip to content

Commit

Permalink
Reponse.mock is setable through options.
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshasselberg committed Oct 2, 2012
1 parent ac8af85 commit 619d7b4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/typhoeus/response.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Response
attr_accessor :options attr_accessor :options


# @api private # @api private
attr_accessor :mock attr_writer :mock


# Create a new response. # Create a new response.
# #
Expand All @@ -41,5 +41,10 @@ def initialize(options = {})
@options = options @options = options
@headers = options[:headers] @headers = options[:headers]
end end

# @api private
def mock
defined?(@mock) ? @mock : options[:mock]
end
end end
end end
27 changes: 27 additions & 0 deletions spec/typhoeus/response_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,4 +13,31 @@
end end
end 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 end

0 comments on commit 619d7b4

Please sign in to comment.