stumb 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,110 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'fileutils'
9
+ require 'spec/rake/spectask'
10
+ require 'lib/stumb'
11
+ include FileUtils
12
+
13
+ NAME = "stumb"
14
+ AUTHOR = "moro"
15
+ EMAIL = "moronatural@gmail.com"
16
+ DESCRIPTION = "store and show stubbed web-request."
17
+ HOMEPAGE = "http://github.com/moro/#{NAME}/"
18
+ BIN_FILES = %w( )
19
+
20
+ VERS = Stumb::Version
21
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
22
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
23
+ RDOC_OPTS = [
24
+ '--title', "#{NAME} documentation",
25
+ "--charset", "utf-8",
26
+ "--opname", "index.html",
27
+ "--line-numbers",
28
+ "--main", "README.rdoc",
29
+ "--inline-source",
30
+ ]
31
+
32
+ task :default => [:spec]
33
+ task :package => [:clean]
34
+
35
+ desc "Run all specs in spec directory"
36
+ Spec::Rake::SpecTask.new(:spec) do |t|
37
+ t.spec_opts = %w[--colour --format progress --loadby --reverse]
38
+ t.spec_files = FileList['spec/**/*_spec.rb']
39
+ end
40
+
41
+ spec = Gem::Specification.new do |s|
42
+ s.name = NAME
43
+ s.version = VERS
44
+ s.platform = Gem::Platform::RUBY
45
+ s.has_rdoc = true
46
+ # s.extra_rdoc_files = ["README.rdoc", "ChangeLog"]
47
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
48
+ s.summary = DESCRIPTION
49
+ s.description = DESCRIPTION
50
+ s.author = AUTHOR
51
+ s.email = EMAIL
52
+ s.homepage = HOMEPAGE
53
+ s.executables = BIN_FILES
54
+ s.bindir = "bin"
55
+ s.require_path = "lib"
56
+ s.test_files = Dir["test/*_test.rb"]
57
+
58
+ #s.add_dependency('activesupport', '>=1.3.1')
59
+ #s.required_ruby_version = '>= 1.8.2'
60
+
61
+ s.files = %w(Rakefile) +
62
+ Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
63
+ Dir.glob("ext/**/*.{h,c,rb}") +
64
+ Dir.glob("examples/**/*.rb") +
65
+ Dir.glob("tools/*.rb") +
66
+ Dir.glob("rails/*.rb")
67
+
68
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
69
+ end
70
+
71
+ Rake::GemPackageTask.new(spec) do |p|
72
+ p.need_tar = true
73
+ p.gem_spec = spec
74
+ end
75
+
76
+ task :install do
77
+ name = "#{NAME}-#{VERS}.gem"
78
+ sh %{rake package}
79
+ sh %{gem install pkg/#{name}}
80
+ end
81
+
82
+ task :uninstall => [:clean] do
83
+ sh %{gem uninstall #{NAME}}
84
+ end
85
+
86
+ desc 'Show information about the gem.'
87
+ task :debug_gem do
88
+ puts spec.to_ruby
89
+ end
90
+
91
+ desc 'Update gem spec'
92
+ task :gemspec do
93
+ open("#{NAME}.gemspec", 'w').write spec.to_ruby
94
+ end
95
+
96
+
97
+ Rake::RDocTask.new do |rdoc|
98
+ rdoc.rdoc_dir = 'html'
99
+ rdoc.options += RDOC_OPTS
100
+ rdoc.template = "resh"
101
+ #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
102
+ if ENV['DOC_FILES']
103
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
104
+ else
105
+ rdoc.rdoc_files.include('README', 'ChangeLog')
106
+ rdoc.rdoc_files.include('lib/**/*.rb')
107
+ rdoc.rdoc_files.include('ext/**/*.c')
108
+ end
109
+ end
110
+
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'rack'
3
+
4
+ module Stumb
5
+ autoload :Stub, 'stumb/stub'
6
+ autoload :Stamp, 'stumb/stamp'
7
+ autoload :StampSheet, 'stumb/stamp_sheet'
8
+
9
+ Version = '0.0.2'
10
+
11
+ def to_app(response, sheet_path = "/sheet", &block)
12
+ Rack::Builder.new {
13
+ use Rack::ShowExceptions
14
+
15
+ stub = Stub.new(*response)
16
+ sheet = StampSheet.new(stub)
17
+
18
+ map(sheet_path) { run sheet }
19
+ instance_eval(&block) if block_given?
20
+ map("/") { run stub }
21
+ }
22
+ end
23
+ module_function :to_app
24
+ end
25
+
@@ -0,0 +1,18 @@
1
+ module Stumb
2
+ class Stamp
3
+ attr_reader :time, :request
4
+ def initialize(req)
5
+ @time = Time.now
6
+ @request = req
7
+ end
8
+
9
+ def body
10
+ return @body if @body
11
+ begin
12
+ @body ||= @request.body.read
13
+ ensure
14
+ @request.body.rewind
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ require 'haml'
2
+ require 'time'
3
+
4
+ module Stumb
5
+ class StampSheet
6
+ def initialize(stub)
7
+ @stub = stub
8
+ @haml = Haml::Engine.new(<<HAML)
9
+ !!!
10
+ %html
11
+ %head
12
+ %body
13
+ %h1 Requests
14
+ %table
15
+ - stamps.each do |stamp|
16
+ %tr
17
+ %td&= stamp.time.iso8601
18
+ %td&= stamp.request.ip
19
+ %td&= stamp.request.request_method
20
+ %td&= stamp.request.fullpath
21
+ %td&= stamp.body
22
+ HAML
23
+ end
24
+
25
+ def call(env)
26
+ [200, {"Content-Type" => "text/html"}, @haml.render(@stub)]
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,17 @@
1
+ require 'rack'
2
+ require 'stumb/stamp'
3
+
4
+ module Stumb
5
+ class Stub
6
+ attr_reader :stamps
7
+ def initialize(*stub_response)
8
+ @stamps = []
9
+ @stub_response = stub_response
10
+ end
11
+
12
+ def call(env)
13
+ @stamps << Stamp.new(Rack::Request.new(env))
14
+ @stub_response
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stumb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - moro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-27 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: store and show stubbed web-request.
17
+ email: moronatural@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - Rakefile
26
+ - lib/stumb/stamp.rb
27
+ - lib/stumb/stamp_sheet.rb
28
+ - lib/stumb/stub.rb
29
+ - lib/stumb.rb
30
+ has_rdoc: true
31
+ homepage: http://github.com/moro/stumb/
32
+ licenses: []
33
+
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --title
37
+ - stumb documentation
38
+ - --charset
39
+ - utf-8
40
+ - --opname
41
+ - index.html
42
+ - --line-numbers
43
+ - --main
44
+ - README.rdoc
45
+ - --inline-source
46
+ - --exclude
47
+ - ^(examples|extras)/
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:
65
+ rubygems_version: 1.3.5
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: store and show stubbed web-request.
69
+ test_files: []
70
+