tivo 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Kevin W. Gisi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = Tivo
2
+
3
+ A VCR-inspired convention-based web-request stubbing mechanism.
4
+
5
+ == ALPHA ALPHA ALPHA Disclaimer
6
+
7
+ This gem is alpha. Very alpha. It should not be used in production. It should not be used as an example of "clean code" or "best practices". It is under heavy development, and may change, be refactored, be completely removed, at a moment's notice. The author disavows any responsibility if your code breaks via its use. Be very certain you know what you're doing if you look at this code - it is, to repeat, alpha.
8
+
9
+ == Installation
10
+
11
+ In your Gemfile, add:
12
+
13
+ gem "tivo"
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Kevin W. Gisi. See MIT-LICENSE for details.
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Tivo'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+ require 'rspec/core/rake_task'
38
+
39
+ desc "Run specs"
40
+ RSpec::Core::RakeTask.new do |t|
41
+ t.rspec_opts = ['--backtrace']
42
+ end
43
+
44
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :tivo do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,24 @@
1
+ module Tivo
2
+ @enabled = true
3
+
4
+ class << self
5
+ def enabled?
6
+ @enabled
7
+ end
8
+
9
+ def enable!
10
+ @enabled = true
11
+ end
12
+
13
+ def disable!
14
+ @enabled = false
15
+ end
16
+ end
17
+ end
18
+
19
+ require_relative 'tivo/pending_request_error'
20
+ require_relative 'tivo/hooks'
21
+
22
+ require_relative 'tivo/extensions/test_unit'
23
+ require_relative 'tivo/extensions/net_http'
24
+ require_relative 'tivo/extensions/rspec'
@@ -0,0 +1,3 @@
1
+ require 'net/http'
2
+
3
+ require_relative 'net_http/net/http'
@@ -0,0 +1,20 @@
1
+ require 'net/http'
2
+
3
+ module Net
4
+ class HTTP
5
+ def request_with_tivo(request, body = nil, &block)
6
+ if Tivo.enabled?
7
+ net_http = self
8
+ protocol = net_http.use_ssl? ? 'https' : 'http'
9
+ path = (request.path =~ /^http/ ? URI.parse(request.path).request_uri : request.path)
10
+ full_path = "#{protocol}://#{net_http.address}:#{net_http.port}#{path}"
11
+ raise Tivo::PendingRequestError, "Intercepted a request to #{full_path}"
12
+ else
13
+ request_without_tivo(request,body,&block)
14
+ end
15
+ end
16
+
17
+ alias_method :request_without_tivo, :request
18
+ alias_method :request, :request_with_tivo
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ if defined?(RSpec)
2
+ require_relative 'rspec/core/example'
3
+ require_relative 'rspec/core/example_group'
4
+ end
@@ -0,0 +1,46 @@
1
+ module RSpec
2
+ module Core
3
+ class Example
4
+
5
+ def run(example_group_instance, reporter)
6
+ @example_group_instance = example_group_instance
7
+ @example_group_instance.example = self
8
+
9
+ start(reporter)
10
+
11
+ begin
12
+ unless pending
13
+ with_around_each_hooks do
14
+ begin
15
+ run_before_each
16
+ @example_group_instance.instance_eval(&@example_block)
17
+ rescue Tivo::PendingRequestError => e
18
+ @pending_declared_in_example = e.message
19
+ rescue Exception => e
20
+ set_exception(e)
21
+ ensure
22
+ run_after_each
23
+ end
24
+ end
25
+ end
26
+ rescue Exception => e
27
+ set_exception(e)
28
+ ensure
29
+ @example_group_instance.instance_variables.each do |ivar|
30
+ @example_group_instance.instance_variable_set(ivar, nil)
31
+ end
32
+ @example_group_instance = nil
33
+
34
+ begin
35
+ assign_auto_description
36
+ rescue Exception => e
37
+ set_exception(e)
38
+ end
39
+ end
40
+
41
+ finish(reporter)
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ module RSpec
2
+ module Core
3
+ class ExampleGroup
4
+ include Tivo::Hooks
5
+
6
+ def self.run_after_all_hooks(example_group_instance)
7
+ return if descendant_filtered_examples.empty?
8
+ assign_before_all_ivars(before_all_ivars, example_group_instance)
9
+
10
+ begin
11
+ run_hook(:after, :all, example_group_instance)
12
+ rescue Tivo::PendingRequestError => e
13
+ RSpec.configuration.reporter.message <<-EOS
14
+
15
+ A Tivo error occurred in an after(:all) hook.
16
+ #{e.class}: #{e.message}
17
+ occurred at #{e.backtrace.first}
18
+
19
+ EOS
20
+ rescue => e
21
+ # TODO: come up with a better solution for this.
22
+ RSpec.configuration.reporter.message <<-EOS
23
+
24
+ An error occurred in an after(:all) hook.
25
+ #{e.class}: #{e.message}
26
+ occurred at #{e.backtrace.first}
27
+
28
+ EOS
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ module Test::Unit
2
+ class TestCase
3
+ include Tivo::Hooks
4
+ end
5
+
6
+ class Runner
7
+ # Overriding of MiniTest::Unit#puke
8
+ def puke klass, meth, e
9
+ # TODO:
10
+ # this overriding is for minitest feature that skip messages are
11
+ # hidden when not verbose (-v), note this is temporally.
12
+ e = case e
13
+ when Tivo::PendingRequestError then
14
+ @skips += 1
15
+ "Skipped:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
16
+ when MiniTest::Skip then
17
+ @skips += 1
18
+ "Skipped:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
19
+ when MiniTest::Assertion then
20
+ @failures += 1
21
+ "Failure:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
22
+ else
23
+ @errors += 1
24
+ bt = MiniTest::filter_backtrace(e.backtrace).join "\n "
25
+ "Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.message}\n #{bt}\n"
26
+ end
27
+ @report << e
28
+ e[0, 1]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+
3
+ require_relative 'test/unit'
@@ -0,0 +1,10 @@
1
+ module Tivo::Hooks
2
+ def without_tivo
3
+ Tivo.disable!
4
+ begin
5
+ yield
6
+ ensure
7
+ Tivo.enable!
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ module Tivo
2
+ class PendingRequestError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Tivo
2
+ VERSION = "0.0.1.alpha"
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'rspec'
2
+
3
+ Dir["#{File.dirname(__FILE__)}/../lib/*.rb"].each { |f| require f }
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'open-uri'
3
+
4
+ describe 'Tivo' do
5
+ it 'should skip tests requiring web requests' do
6
+ open('http://google.com')
7
+ end
8
+
9
+ it 'should allow tivo-escaped blocks' do
10
+ without_tivo do
11
+ open('http://google.com')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ Dir["#{File.dirname(__FILE__)}/../lib/*.rb"].each { |f| require f }
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+ require 'open-uri'
3
+
4
+ class TivoTest < Test::Unit::TestCase
5
+
6
+ def test_skip_test_requiring_web_requests
7
+ open('http://google.com')
8
+ end
9
+
10
+ def test_allow_tivo_escaped_blocks
11
+ without_tivo do
12
+ open('http://google.com')
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tivo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Kevin W. Gisi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: A convention-based web-request stubbing mechanism.
31
+ email:
32
+ - kevin@kevingisi.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/tasks/tivo_tasks.rake
38
+ - lib/tivo/extensions/net_http/net/http.rb
39
+ - lib/tivo/extensions/net_http.rb
40
+ - lib/tivo/extensions/rspec/core/example.rb
41
+ - lib/tivo/extensions/rspec/core/example_group.rb
42
+ - lib/tivo/extensions/rspec.rb
43
+ - lib/tivo/extensions/test/unit.rb
44
+ - lib/tivo/extensions/test_unit.rb
45
+ - lib/tivo/hooks.rb
46
+ - lib/tivo/pending_request_error.rb
47
+ - lib/tivo/version.rb
48
+ - lib/tivo.rb
49
+ - MIT-LICENSE
50
+ - Rakefile
51
+ - README.rdoc
52
+ - test/test_helper.rb
53
+ - test/tivo_test.rb
54
+ - spec/spec_helper.rb
55
+ - spec/tivo_spec.rb
56
+ homepage: http://github.com/gisikw/tivo
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ segments:
69
+ - 0
70
+ hash: 2168009181208321104
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>'
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.1
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.23
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: A convention-based web-request stubbing mechanism.
83
+ test_files:
84
+ - test/test_helper.rb
85
+ - test/tivo_test.rb
86
+ - spec/spec_helper.rb
87
+ - spec/tivo_spec.rb