Skip to content

Commit

Permalink
Merge pull request #49 from SalesLoft/pr/17
Browse files Browse the repository at this point in the history
Resolve merge conflicts for #17
  • Loading branch information
sionide21 authored Aug 29, 2023
2 parents 933701f + 3dd1d96 commit 066ddae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/tcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ def save_session
def use_cassette(name, options = {}, &block)
raise ArgumentError, "`TCR.use_cassette` requires a block." unless block
TCR.cassette = Cassette.new(name)
yield
ret_val = yield
TCR.cassette.save
TCR.cassette.check_hits_all_sessions if options[:hit_all] || configuration.hit_all
ret_val
ensure
TCR.cassette = nil
end
Expand All @@ -51,8 +52,9 @@ def turned_off(&block)
raise ArgumentError, "`TCR.turned_off` requires a block." unless block
current_hook_tcp_ports = configuration.hook_tcp_ports
configuration.hook_tcp_ports = []
yield
ret_val = yield
configuration.hook_tcp_ports = current_hook_tcp_ports
ret_val
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/tcr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
}.to raise_error(ArgumentError)
end

it "returns the value" do
expect(TCR.turned_off { :foobar }).to eq(:foobar)
end

it "disables hooks within the block" do
TCR.configure { |c| c.hook_tcp_ports = [2525] }
TCR.turned_off do
Expand Down Expand Up @@ -150,6 +154,10 @@
}.to raise_error(TCR::NoCassetteError)
end

it "returns the value" do
expect(TCR.use_cassette("test") { :foobar }).to eq(:foobar)
end

it "requires a block to call" do
expect {
TCR.use_cassette("test")
Expand Down

0 comments on commit 066ddae

Please sign in to comment.