web_fixtures 0.1.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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.md +63 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/bin/web_fixtures +7 -0
- data/lib/web_fixtures/base.rb +50 -0
- data/lib/web_fixtures/dsl.rb +53 -0
- data/lib/web_fixtures/request.rb +73 -0
- data/lib/web_fixtures.rb +3 -0
- data/spec/demo.rb +7 -0
- data/spec/demo2.rb +1 -0
- data/spec/fixtures/google.txt +1 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/web_fixtures/base_spec.rb +105 -0
- data/spec/web_fixtures/dsl_spec.rb +60 -0
- data/spec/web_fixtures/request_spec.rb +152 -0
- data/web_fixtures.gemspec +68 -0
- metadata +107 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jeff Tucker
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# WebFixtures
|
2
|
+
|
3
|
+
WebFixtures lets you easily generate fixture files for web service response.
|
4
|
+
|
5
|
+
# my_fixtures.rb
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'web_fixtures'
|
9
|
+
|
10
|
+
WebFixtures.generate do
|
11
|
+
|
12
|
+
storage_path "spec/fixtures"
|
13
|
+
include_headers true
|
14
|
+
authenticate false
|
15
|
+
|
16
|
+
get "http://www.google.com"
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
Also comes with a command line tool `web_fixtures` which allow you to run simple DSL-only files:
|
21
|
+
|
22
|
+
# my_fixtures.txt
|
23
|
+
|
24
|
+
include_headers true
|
25
|
+
authenticate true
|
26
|
+
|
27
|
+
get "http://api.foursquare.com/v1/user"
|
28
|
+
get "http://www.foursquare.com", :authenticate => false
|
29
|
+
|
30
|
+
## File Storage
|
31
|
+
|
32
|
+
The generated files are stored to the storage_path in subfolders according to the requested domain name. The filename is build according to the path-part of the URI. e.g., the result of a request to "http://www.google.com/images/" will be stored in `./fixtures/www.google.com/images.txt`.
|
33
|
+
|
34
|
+
## Authentication
|
35
|
+
|
36
|
+
WebFixtures supports authentication through Basic HTTP Auth. After setting `authenticate true`, WebFixtures will ask for your username and password:
|
37
|
+
|
38
|
+
$ web_fixtures /path/to/dsl.file
|
39
|
+
Username: my@email.com
|
40
|
+
Password:
|
41
|
+
$
|
42
|
+
|
43
|
+
## DSL Options
|
44
|
+
|
45
|
+
* Supports `get`, `post`, `put` and `delete` requests
|
46
|
+
* Can enable/disable storing header data with `include_headers` [default: true]
|
47
|
+
* Specify storage path for fixtures with `storage_path` [default: './fixtures']
|
48
|
+
* Supports HTTP Basic Auth with the `authenticate` option [default: false]
|
49
|
+
* These options are available as both top-level methods and inline options for overriding defaults on a single request.
|
50
|
+
|
51
|
+
## Note on Patches/Pull Requests
|
52
|
+
|
53
|
+
* Fork the project.
|
54
|
+
* Make your feature addition or bug fix.
|
55
|
+
* Add tests for it. This is important so I don't break it in a
|
56
|
+
future version unintentionally.
|
57
|
+
* Commit, do not mess with rakefile, version, or history.
|
58
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
59
|
+
* Send me a pull request. Bonus points for topic branches.
|
60
|
+
|
61
|
+
## Copyright
|
62
|
+
|
63
|
+
Copyright (c) 2010 Jeff Tucker. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "web_fixtures"
|
8
|
+
gem.summary = "WebFixtures lets you easily generate fixture files for web service responses"
|
9
|
+
gem.description = "WebFixtures lets you easily generate fixture files for web service responses"
|
10
|
+
gem.email = "trydionel@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/trydionel/web_fixtures"
|
12
|
+
gem.authors = ["Jeff Tucker"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "web_fixtures #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/web_fixtures
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module WebFixtures
|
2
|
+
|
3
|
+
Version = File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION'))
|
4
|
+
|
5
|
+
def self.generate(&block)
|
6
|
+
WebFixtures::Base.new(&block)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Base < Array
|
10
|
+
|
11
|
+
attr_accessor :filename
|
12
|
+
|
13
|
+
def initialize(filename = nil, &block)
|
14
|
+
@filename = filename
|
15
|
+
@block = block
|
16
|
+
end
|
17
|
+
|
18
|
+
def dsl
|
19
|
+
@dsl ||= WebFixtures::DSL.new(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def run!
|
23
|
+
if @block
|
24
|
+
dsl.instance_eval(&@block)
|
25
|
+
else
|
26
|
+
dsl.instance_eval(File.read(filename), filename)
|
27
|
+
end
|
28
|
+
|
29
|
+
store!
|
30
|
+
return 0
|
31
|
+
rescue Exception
|
32
|
+
return 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def store!
|
36
|
+
credentials = {}
|
37
|
+
self.each do |request|
|
38
|
+
request.username = credentials[:username] if credentials[:username]
|
39
|
+
request.password = credentials[:password] if credentials[:password]
|
40
|
+
|
41
|
+
request.store!
|
42
|
+
|
43
|
+
credentials[:username] = request.username
|
44
|
+
credentials[:password] = request.password
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module WebFixtures
|
2
|
+
class DSL
|
3
|
+
|
4
|
+
attr_accessor :base
|
5
|
+
attr_accessor :default_options
|
6
|
+
|
7
|
+
@@default_options = {
|
8
|
+
:include_headers => true,
|
9
|
+
:authenticate => false,
|
10
|
+
:root_path => "./fixtures"
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(base, options = {})
|
14
|
+
@base = base
|
15
|
+
@default_options = @@default_options.merge(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def include_headers(choice)
|
19
|
+
default_options[:include_headers] = choice
|
20
|
+
end
|
21
|
+
|
22
|
+
def authenticate(choice)
|
23
|
+
default_options[:authenticate] = choice
|
24
|
+
end
|
25
|
+
|
26
|
+
def storage_path(path)
|
27
|
+
default_options[:root_path] = path
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(url, options = {})
|
31
|
+
add_request(:get, url, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def post(url, options = {})
|
35
|
+
add_request(:post, url, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def put(url, options = {})
|
39
|
+
add_request(:put, url, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete(url, options = {})
|
43
|
+
add_request(:delete, url, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def add_request(method, url, options)
|
49
|
+
base << WebFixtures::Request.new(method, url, default_options.merge(options))
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module WebFixtures
|
2
|
+
class Request
|
3
|
+
|
4
|
+
attr_accessor :method
|
5
|
+
attr_accessor :uri
|
6
|
+
attr_accessor :options
|
7
|
+
|
8
|
+
attr_accessor :input
|
9
|
+
attr_accessor :output
|
10
|
+
|
11
|
+
attr_accessor :username, :password
|
12
|
+
|
13
|
+
def initialize(method, uri, options = {}, input = STDIN, output = STDOUT)
|
14
|
+
@method = method
|
15
|
+
@uri = uri
|
16
|
+
@options = options
|
17
|
+
|
18
|
+
@input = input
|
19
|
+
@output = output
|
20
|
+
end
|
21
|
+
|
22
|
+
def store!
|
23
|
+
`mkdir -p \"#{storage_path}\" && #{curl_command}`
|
24
|
+
end
|
25
|
+
|
26
|
+
def curl_command
|
27
|
+
command = "curl -s"
|
28
|
+
command << " -i" if options[:include_headers]
|
29
|
+
command << " -u #{collect_username}:#{collect_password}" if options[:authenticate]
|
30
|
+
command << " -X #{method.to_s.upcase}" if method != :get
|
31
|
+
command << " -o \"#{output_file}\""
|
32
|
+
command << " \"#{uri}\""
|
33
|
+
command
|
34
|
+
end
|
35
|
+
|
36
|
+
def uri_components
|
37
|
+
@uri_components ||= uri.split('/')
|
38
|
+
end
|
39
|
+
|
40
|
+
def storage_path
|
41
|
+
root = options[:root_path] || "."
|
42
|
+
directory = uri_components[2]
|
43
|
+
|
44
|
+
File.join(root, directory)
|
45
|
+
end
|
46
|
+
|
47
|
+
def filename
|
48
|
+
title = uri_components[3..-1].join("_")
|
49
|
+
(title.empty? ? "root" : title) + ".txt"
|
50
|
+
end
|
51
|
+
|
52
|
+
def output_file
|
53
|
+
File.join(storage_path, filename)
|
54
|
+
end
|
55
|
+
|
56
|
+
def collect_username
|
57
|
+
return username if username
|
58
|
+
return nil unless options[:authenticate]
|
59
|
+
|
60
|
+
output.print "Username: "
|
61
|
+
@username = input.gets.chomp
|
62
|
+
end
|
63
|
+
|
64
|
+
def collect_password
|
65
|
+
return password if password
|
66
|
+
return nil unless options[:authenticate]
|
67
|
+
|
68
|
+
output.print "Password: "
|
69
|
+
@password = input.gets.chomp
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
data/lib/web_fixtures.rb
ADDED
data/spec/demo.rb
ADDED
data/spec/demo2.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
get "http://api.foursquare.com/v1/user", :authenticate => true
|
@@ -0,0 +1 @@
|
|
1
|
+
get "http://www.google.com"
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'web_fixtures'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
|
7
|
+
# Prevent `cmd` from actually executing
|
8
|
+
module Kernel
|
9
|
+
def `(cmd)
|
10
|
+
cmd
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Spec::Runner.configure do |config|
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WebFixtures::Base do
|
4
|
+
|
5
|
+
it { should be_a(Array) }
|
6
|
+
its(:dsl) { should be_a(WebFixtures::DSL) }
|
7
|
+
|
8
|
+
it "should expose a version number" do
|
9
|
+
WebFixtures::Version.should == File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION'))
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#run!" do
|
13
|
+
|
14
|
+
before { @file = File.join(File.dirname(__FILE__), '..', 'fixtures','google.txt') }
|
15
|
+
subject { WebFixtures::Base.new(@file) }
|
16
|
+
|
17
|
+
context "when given a file" do
|
18
|
+
|
19
|
+
it "should evaluate the given file" do
|
20
|
+
subject.dsl.should_receive(:instance_eval).
|
21
|
+
with(File.read(@file), @file)
|
22
|
+
|
23
|
+
subject.run!
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should store the resulting requests" do
|
27
|
+
subject.should_receive(:store!)
|
28
|
+
|
29
|
+
subject.run!
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return 0" do
|
33
|
+
subject.run!.should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return 1 on errors" do
|
37
|
+
subject.stub!(:store!).and_raise(Exception)
|
38
|
+
|
39
|
+
subject.run!.should == 1
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when given a block" do
|
45
|
+
|
46
|
+
before { @block = Proc.new { get "http://www.google.com" } }
|
47
|
+
subject { WebFixtures::Base.new(&@block) }
|
48
|
+
|
49
|
+
it "should evaluate the given block" do
|
50
|
+
subject.dsl.should_receive(:instance_eval)
|
51
|
+
|
52
|
+
subject.run!
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should store the resulting requests" do
|
56
|
+
subject.should_receive(:store!)
|
57
|
+
|
58
|
+
subject.run!
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return 0" do
|
62
|
+
subject.run!.should == 0
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return 1 on errors" do
|
66
|
+
subject.stub!(:store!).and_raise(Exception)
|
67
|
+
|
68
|
+
subject.run!.should == 1
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#store!" do
|
76
|
+
|
77
|
+
before(:each) do
|
78
|
+
@stdin = StringIO.new
|
79
|
+
@stdout = StringIO.new
|
80
|
+
|
81
|
+
subject << WebFixtures::Request.new(:get, "http://www.google.com", { :authenticate => true }, @stdin, @stdout)
|
82
|
+
subject << WebFixtures::Request.new(:get, "http://www.google.com", {}, @stdin, @stdout)
|
83
|
+
subject << WebFixtures::Request.new(:get, "http://www.google.com", {}, @stdin, @stdout)
|
84
|
+
|
85
|
+
subject[0].username = "foo"
|
86
|
+
subject[0].password = "bar"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should call #store! on each of its elements" do
|
90
|
+
subject.each { |request| request.should_receive(:store!) }
|
91
|
+
subject.store!
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should pass credentials along to the following requests" do
|
95
|
+
subject[1...-1].each do |request|
|
96
|
+
request.should_receive(:username=).with("foo")
|
97
|
+
request.should_receive(:password=).with("bar")
|
98
|
+
end
|
99
|
+
|
100
|
+
subject.store!
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WebFixtures::DSL do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@base = WebFixtures::Base.new
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
WebFixtures::DSL.new(@base)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "#include_headers should set the :include_headers option" do
|
14
|
+
subject.include_headers true
|
15
|
+
subject.default_options[:include_headers].should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "#authenticate should set the :authenticate option" do
|
19
|
+
subject.authenticate true
|
20
|
+
subject.default_options[:authenticate].should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "#storage_path should set the :root_path option" do
|
24
|
+
subject.storage_path './foo/bar'
|
25
|
+
subject.default_options[:root_path].should == "./foo/bar"
|
26
|
+
end
|
27
|
+
|
28
|
+
[:get, :post, :put, :delete].each do |method|
|
29
|
+
|
30
|
+
describe "##{method}" do
|
31
|
+
|
32
|
+
it "should build a new request object" do
|
33
|
+
WebFixtures::Request.should_receive(:new).
|
34
|
+
with(method,
|
35
|
+
"http://www.google.com",
|
36
|
+
subject.default_options)
|
37
|
+
|
38
|
+
subject.send method, "http://www.google.com"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should add the request to the base" do
|
42
|
+
expect {
|
43
|
+
subject.send method, "http://www.google.com"
|
44
|
+
}.to change(@base, :size).by(1)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should allow overrides for default options" do
|
48
|
+
WebFixtures::Request.should_receive(:new).
|
49
|
+
with(method,
|
50
|
+
"http://www.google.com",
|
51
|
+
hash_including(:authenticate => true))
|
52
|
+
|
53
|
+
subject.send method, "http://www.google.com", :authenticate => true
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WebFixtures::Request do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@stdin = StringIO.new
|
7
|
+
@stdout = StringIO.new
|
8
|
+
end
|
9
|
+
|
10
|
+
subject do
|
11
|
+
WebFixtures::Request.new(:get, 'http://www.google.com/translate', {}, @stdin, @stdout)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should build the storage path based on the URI domain" do
|
15
|
+
subject.storage_path.should == "./www.google.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should build the filename based on the URI path" do
|
19
|
+
subject.filename.should == "translate.txt"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should build the output file from the storage path and filename" do
|
23
|
+
subject.output_file.should == './www.google.com/translate.txt'
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#collect_username" do
|
27
|
+
|
28
|
+
it "should return nil if not authenticating" do
|
29
|
+
subject.collect_username.should be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when authenticating" do
|
33
|
+
|
34
|
+
before(:each) do
|
35
|
+
subject.options = { :authenticate => true }
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return the username if one is set" do
|
39
|
+
subject.username = "foo"
|
40
|
+
subject.collect_username.should == "foo"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should request a username from the user if one isn't set" do
|
44
|
+
@stdin.should_receive(:gets).and_return("bar\n")
|
45
|
+
subject.collect_username
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return the user input after requested" do
|
49
|
+
@stdin << "bar"
|
50
|
+
@stdin.rewind
|
51
|
+
subject.collect_username
|
52
|
+
|
53
|
+
subject.username.should == "bar"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#collect_password" do
|
61
|
+
|
62
|
+
it "should return nil if not authenticating" do
|
63
|
+
subject.collect_password.should be_nil
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when authenticating" do
|
67
|
+
|
68
|
+
before(:each) do
|
69
|
+
subject.options = { :authenticate => true }
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return the password if one is set" do
|
73
|
+
subject.password = "foo"
|
74
|
+
subject.collect_password.should == "foo"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should request a password from the user if one isn't set" do
|
78
|
+
@stdin.should_receive(:gets).and_return("bar\n")
|
79
|
+
subject.collect_password
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return the user input after requested" do
|
83
|
+
@stdin << "bar\n\n"
|
84
|
+
@stdin.rewind
|
85
|
+
subject.collect_password
|
86
|
+
|
87
|
+
subject.password.should == "bar"
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#store!" do
|
95
|
+
|
96
|
+
it "should ensure the output path exists before getting the URI" do
|
97
|
+
subject.store!.should include('mkdir -p "./www.google.com"')
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should include the curl command" do
|
101
|
+
subject.store!.should include(subject.curl_command)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#curl_command" do
|
107
|
+
|
108
|
+
it "should always include -s" do
|
109
|
+
subject.curl_command.should include('-s')
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should should not include -i when not including headers" do
|
113
|
+
subject.curl_command.should_not include('-i')
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should include -i when including headers" do
|
117
|
+
subject.options = { :include_headers => true }
|
118
|
+
subject.curl_command.should include('-i')
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should not include -u when authenticating" do
|
122
|
+
subject.curl_command.should_not include('-u')
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should include -u user:pass when authenticating" do
|
126
|
+
subject.options = { :authenticate => true }
|
127
|
+
subject.username = "foo"
|
128
|
+
subject.password = "bar"
|
129
|
+
|
130
|
+
subject.curl_command.should include('-u foo:bar')
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should not include -X for GET requests" do
|
134
|
+
subject.curl_command.should_not include('-X GET')
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should include -X for non-GET requests" do
|
138
|
+
subject.method = :post
|
139
|
+
subject.curl_command.should include('-X POST')
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should include -o output_file" do
|
143
|
+
subject.curl_command.should include('-o "./www.google.com/translate.txt"')
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should include the url" do
|
147
|
+
subject.curl_command.should include("http://www.google.com/translate")
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{web_fixtures}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jeff Tucker"]
|
12
|
+
s.date = %q{2010-09-19}
|
13
|
+
s.default_executable = %q{web_fixtures}
|
14
|
+
s.description = %q{WebFixtures lets you easily generate fixture files for web service responses}
|
15
|
+
s.email = %q{trydionel@gmail.com}
|
16
|
+
s.executables = ["web_fixtures"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/web_fixtures",
|
29
|
+
"lib/web_fixtures.rb",
|
30
|
+
"lib/web_fixtures/base.rb",
|
31
|
+
"lib/web_fixtures/dsl.rb",
|
32
|
+
"lib/web_fixtures/request.rb",
|
33
|
+
"spec/fixtures/google.txt",
|
34
|
+
"spec/spec.opts",
|
35
|
+
"spec/spec_helper.rb",
|
36
|
+
"spec/web_fixtures/base_spec.rb",
|
37
|
+
"spec/web_fixtures/dsl_spec.rb",
|
38
|
+
"spec/web_fixtures/request_spec.rb",
|
39
|
+
"web_fixtures.gemspec"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/trydionel/web_fixtures}
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = %q{1.3.7}
|
45
|
+
s.summary = %q{WebFixtures lets you easily generate fixture files for web service responses}
|
46
|
+
s.test_files = [
|
47
|
+
"spec/demo.rb",
|
48
|
+
"spec/demo2.rb",
|
49
|
+
"spec/spec_helper.rb",
|
50
|
+
"spec/web_fixtures/base_spec.rb",
|
51
|
+
"spec/web_fixtures/dsl_spec.rb",
|
52
|
+
"spec/web_fixtures/request_spec.rb"
|
53
|
+
]
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
|
+
s.specification_version = 3
|
58
|
+
|
59
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: web_fixtures
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jeff Tucker
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-19 00:00:00 -04:00
|
19
|
+
default_executable: web_fixtures
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: WebFixtures lets you easily generate fixture files for web service responses
|
38
|
+
email: trydionel@gmail.com
|
39
|
+
executables:
|
40
|
+
- web_fixtures
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.md
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- bin/web_fixtures
|
54
|
+
- lib/web_fixtures.rb
|
55
|
+
- lib/web_fixtures/base.rb
|
56
|
+
- lib/web_fixtures/dsl.rb
|
57
|
+
- lib/web_fixtures/request.rb
|
58
|
+
- spec/fixtures/google.txt
|
59
|
+
- spec/spec.opts
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
- spec/web_fixtures/base_spec.rb
|
62
|
+
- spec/web_fixtures/dsl_spec.rb
|
63
|
+
- spec/web_fixtures/request_spec.rb
|
64
|
+
- web_fixtures.gemspec
|
65
|
+
- spec/demo.rb
|
66
|
+
- spec/demo2.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/trydionel/web_fixtures
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --charset=UTF-8
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.3.7
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: WebFixtures lets you easily generate fixture files for web service responses
|
101
|
+
test_files:
|
102
|
+
- spec/demo.rb
|
103
|
+
- spec/demo2.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/web_fixtures/base_spec.rb
|
106
|
+
- spec/web_fixtures/dsl_spec.rb
|
107
|
+
- spec/web_fixtures/request_spec.rb
|