fakeweb_curb-fu 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,8 @@
1
+ Manifest
2
+ README.rdoc
3
+ Rakefile
4
+ lib/fakeweb_curb-fu.rb
5
+ spec/fixtures/response.html
6
+ spec/lib/fakeweb_curb-fu_spec.rb
7
+ spec/spec_helper.rb
8
+ tasks/fakeweb_curb-fu.rake
data/README.rdoc ADDED
@@ -0,0 +1,34 @@
1
+ = fakeweb_curb-fu
2
+
3
+ fakeweb_curb-fu is a helper for faking CurbFu web requests. It is inspired on FakeWeb gem, that doesn't work with CurbFu.
4
+
5
+ == Installation
6
+
7
+ To get it, install the latest gem directly from Gemcutter (currently 0.0.1):
8
+
9
+ sudo gem install fakeweb_curb-fu
10
+
11
+ == Examples
12
+
13
+ require 'rubygems'
14
+ require 'fakeweb_curb-fu'
15
+
16
+ FakeWebCurbFu.register_uri("http://example.com/test1," "/path/to/expected/response")
17
+
18
+ Then, when a request to http:://example.com/test1 is made via CurbFu, the contents of the /path/to/exptected/response file will be returned, like this:
19
+
20
+ CurbFu.get("http://example.com/test1").body => # contents of /path/to/expected/response
21
+
22
+ You can also remove registered uri's like this:
23
+
24
+ FakeWebCurbFu.unregister_uri('http://example.com')
25
+
26
+ == License
27
+
28
+ Copyright (c) 2010 Marcelo Giorgi
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'echoe'
3
+
4
+ # PACKAGING ============================================================
5
+
6
+ Echoe.new('fakeweb_curb-fu', '0.0.1') do |p|
7
+ p.description = ''
8
+ p.url = 'http://github.com/marklazz/fakeweb_curb-fu'
9
+ p.author = 'Marcelo Giorgi'
10
+ p.email = 'marklazz.uy@gmail.com'
11
+ p.ignore_pattern = [ 'tmp/*', 'script/*', '*.sh' ]
12
+ p.runtime_dependencies = []
13
+ p.development_dependencies = [ 'spec' ]
14
+ end
15
+
16
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{fakeweb_curb-fu}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Marcelo Giorgi"]
9
+ s.date = %q{2010-10-14}
10
+ s.description = %q{}
11
+ s.email = %q{marklazz.uy@gmail.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/fakeweb_curb-fu.rb", "tasks/fakeweb_curb-fu.rake"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "fakeweb_curb-fu.gemspec", "lib/fakeweb_curb-fu.rb", "spec/fixtures/response.html", "spec/lib/fakeweb_curb-fu_spec.rb", "spec/spec_helper.rb", "tasks/fakeweb_curb-fu.rake"]
14
+ s.homepage = %q{http://github.com/marklazz/fakeweb_curb-fu}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Fakeweb_curb-fu", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{fakeweb_curb-fu}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ s.add_development_dependency(%q<spec>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<spec>, [">= 0"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<spec>, [">= 0"])
32
+ end
33
+ end
@@ -0,0 +1,71 @@
1
+ require 'rubygems'
2
+ require 'curb-fu'
3
+
4
+ class FakeWebCurbFu
5
+
6
+ VERSION = '0.0.1'
7
+
8
+ class << self
9
+
10
+ unless defined? @uris
11
+ @uris = nil
12
+ end
13
+
14
+ def uris
15
+ @uris
16
+ end
17
+
18
+ def register_uri(url, path)
19
+ @uris ||= {}
20
+ if @uris[url]
21
+ @uris[url]
22
+ elsif File.exists?(path)
23
+ @uris[url] = fixture_contents(path)
24
+ end
25
+ end
26
+
27
+ def unregister_uri(url)
28
+ @uris ||= {}
29
+ @uris.delete(url)
30
+ end
31
+
32
+ def get(url)
33
+ @uris[url]
34
+ end
35
+
36
+ private
37
+
38
+ def fixture_contents(path)
39
+ File.open(path) do |file|
40
+ return "".tap do |content|
41
+ file.each_line { |line| content.concat(line) }
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ class FakeResponseCurbFu
49
+ attr_reader :body
50
+
51
+ def initialize(body)
52
+ @body = body
53
+ end
54
+ end
55
+
56
+ module CurbFu
57
+
58
+ class << self
59
+
60
+ def get_with_fake_uris(uri)
61
+ if (content = FakeWebCurbFu.get(uri))
62
+ FakeResponseCurbFu.new(content)
63
+ else
64
+ get_without_fake_uris(uri)
65
+ end
66
+ end
67
+
68
+ alias_method :get_without_fake_uris, :get
69
+ alias_method :get, :get_with_fake_uris
70
+ end
71
+ end
@@ -0,0 +1,4 @@
1
+ <html>
2
+ <head></head>
3
+ <body>RESPONSE BODY!</body>
4
+ </html>
@@ -0,0 +1,26 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe FakeWebCurbFu do
4
+
5
+ context 'http://marklazz.com is not registered' do
6
+
7
+ before do
8
+ FakeWebCurbFu.unregister_uri('http://marklazz.com')
9
+ end
10
+
11
+ it 'should return the result of CurbFu' do
12
+ CurbFu.get('http://marklazz.com').body.should =~ /#{Regexp.escape("I'm an IT professional doing freelance Web Development and Consulting work over the Internet. In particular, I'm focusing my work on Ruby On Rails development and Agile Methodologies")}/
13
+ end
14
+ end
15
+
16
+ context 'http://marklazz.com is registered to return the contents of result.html' do
17
+
18
+ before do
19
+ FakeWebCurbFu.register_uri('http://marklazz.com', File.join(File.dirname(__FILE__), '..', 'fixtures', 'response.html'))
20
+ end
21
+
22
+ it 'shuold return the contents of result.html' do
23
+ CurbFu.get('http://marklazz.com').body.should =~ /#{Regexp.escape("RESPONSE BODY!")}/
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'lib/fakeweb_curb-fu'
@@ -0,0 +1,65 @@
1
+ require 'rake/clean'
2
+ require 'fileutils'
3
+ require 'date'
4
+ require 'spec/rake/spectask'
5
+ require 'hanna/rdoctask'
6
+
7
+ # Removes spec task defiened in dependency gems
8
+ module Rake
9
+ def self.remove_task(task_name)
10
+ Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
11
+ end
12
+ end
13
+ Rake.remove_task 'spec'
14
+
15
+ def source_version
16
+ line = File.read('lib/fakeweb_curb-fu.rb')[/^\s*VERSION = .*/]
17
+ line.match(/.*VERSION = '(.*)'/)[1]
18
+ end
19
+
20
+ # SPECS ===============================================================
21
+
22
+ Spec::Rake::SpecTask.new(:spec) do |t|
23
+ t.spec_opts = ['--color']
24
+ t.rcov = false
25
+ t.spec_files = FileList['spec/lib/*_spec.rb']
26
+ end
27
+
28
+ task :default => :spec
29
+
30
+ # Rcov ================================================================
31
+ namespace :spec do
32
+ desc 'Mesures test coverage'
33
+ task :coverage do
34
+ rm_f "coverage"
35
+ rcov = "rcov --text-summary -Ilib"
36
+ system("#{rcov} --no-html --no-color spec/lib/*_spec.rb")
37
+ end
38
+ end
39
+
40
+ # Website =============================================================
41
+ # Building docs requires HAML and the hanna gem:
42
+ # gem install mislav-hanna --source=http://gems.github.com
43
+
44
+ desc 'Generate RDoc under doc/api'
45
+ task 'doc' => ['doc:api']
46
+
47
+ task 'doc:api' => ['doc/api/index.html']
48
+
49
+ file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
50
+ require 'rbconfig'
51
+ hanna = RbConfig::CONFIG['ruby_install_name'].sub('ruby', 'hanna')
52
+ rb_files = f.prerequisites
53
+ sh((<<-end).gsub(/\s+/, ' '))
54
+ #{hanna}
55
+ --charset utf8
56
+ --fmt html
57
+ --inline-source
58
+ --line-numbers
59
+ --main README.rdoc
60
+ --op doc/api
61
+ --title 'RTT API Documentation'
62
+ #{rb_files.join(' ')}
63
+ end
64
+ end
65
+ CLEAN.include 'doc/api'
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fakeweb_curb-fu
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Marcelo Giorgi
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-14 00:00:00 -02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: spec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: ""
36
+ email: marklazz.uy@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ - lib/fakeweb_curb-fu.rb
44
+ - tasks/fakeweb_curb-fu.rake
45
+ files:
46
+ - Manifest
47
+ - README.rdoc
48
+ - Rakefile
49
+ - fakeweb_curb-fu.gemspec
50
+ - lib/fakeweb_curb-fu.rb
51
+ - spec/fixtures/response.html
52
+ - spec/lib/fakeweb_curb-fu_spec.rb
53
+ - spec/spec_helper.rb
54
+ - tasks/fakeweb_curb-fu.rake
55
+ has_rdoc: true
56
+ homepage: http://github.com/marklazz/fakeweb_curb-fu
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --line-numbers
62
+ - --inline-source
63
+ - --title
64
+ - Fakeweb_curb-fu
65
+ - --main
66
+ - README.rdoc
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 11
84
+ segments:
85
+ - 1
86
+ - 2
87
+ version: "1.2"
88
+ requirements: []
89
+
90
+ rubyforge_project: fakeweb_curb-fu
91
+ rubygems_version: 1.3.7
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: ""
95
+ test_files: []
96
+