Shopify-tinfoil 0.9.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,6 @@
1
+ === 1.0.0 / 2009-04-07
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/tinfoil.rb
6
+ test/test_tinfoil.rb
@@ -0,0 +1,7 @@
1
+ = tinfoil
2
+
3
+ * http://github.com/Shopify/tinfoil
4
+
5
+ == DESCRIPTION:
6
+
7
+ Prevent remote calls from your unit tests
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'hoe'
4
+
5
+ PKG_VERSION = "0.9.0"
6
+ PKG_NAME = "tinfoil"
7
+ PKG_DESC = "Prevent remote calls from your unit tests"
8
+
9
+ Hoe.new(PKG_NAME, PKG_VERSION) do |p|
10
+ p.summary = PKG_DESC
11
+ p.description = PKG_DESC
12
+ p.author = "Shopify"
13
+ p.email = "developers@shopify.com"
14
+ p.url = "http://github.com/Shopify/tinfoil"
15
+ end
@@ -0,0 +1,38 @@
1
+ require 'net/http'
2
+ require 'test/unit'
3
+
4
+ class Net::HTTP
5
+ def self.allow_remote_calls
6
+ @@allow_remote_calls ||= false
7
+ end
8
+
9
+ def self.allow_remote_calls=(value)
10
+ @@allow_remote_calls = value
11
+ end
12
+
13
+ class BlockedRequest < StandardError
14
+ end
15
+
16
+ [:get, :post, :put, :head, :options, :start].each do |method|
17
+
18
+ define_method("#{method}_with_interception") do |*a|
19
+ if self.class.allow_remote_calls
20
+ send("#{method}_without_interception", *a)
21
+ else
22
+ raise BlockedRequest, "Intercepted #{method.to_s.upcase} in test environment"
23
+ end
24
+ end
25
+
26
+ alias_method "#{method}_without_interception", method
27
+ alias_method method, "#{method}_with_interception"
28
+ end
29
+ end
30
+
31
+ class Test::Unit::TestCase
32
+ def allow_remote_http
33
+ Net::HTTP.allow_remote_calls = true
34
+ yield
35
+ ensure
36
+ Net::HTTP.allow_remote_calls = false
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'mocha'
3
+ require File.dirname(__FILE__) + '/../lib/tinfoil'
4
+
5
+ class TinfoilTest < Test::Unit::TestCase
6
+ def test_block_attempted_remote_call
7
+ assert_raises(Net::HTTP::BlockedRequest) do
8
+ Net::HTTP.get_response('www.google.ca', '/')
9
+ end
10
+ end
11
+
12
+ def test_allow_remote_call_within_block
13
+ Net::HTTP.any_instance.expects(:start)
14
+ Net::HTTP.get_response('www.google.ca', '/')
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Shopify-tinfoil
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Shopify
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-07 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.2
24
+ version:
25
+ description: Prevent remote calls from your unit tests
26
+ email: developers@shopify.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - lib/tinfoil.rb
41
+ - test/test_tinfoil.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/Shopify/tinfoil
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --main
47
+ - README.txt
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project: tinfoil
65
+ rubygems_version: 1.2.0
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: Prevent remote calls from your unit tests
69
+ test_files:
70
+ - test/test_tinfoil.rb