mascut 0.0.4 → 0.0.5
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/HISTORY.rdoc +4 -0
- data/Rakefile +7 -6
- data/VERSION +1 -1
- data/lib/mascut/mascut.rb +19 -6
- data/lib/mascut/option.rb +4 -0
- data/spec/mascut/mascut_spec.rb +124 -0
- data/spec/mascut/option_spec.rb +94 -0
- data/spec/mascut_spec.rb +4 -5
- data/spec/spec_helper.rb +6 -5
- metadata +26 -8
data/HISTORY.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -4,14 +4,15 @@ require 'rake'
|
|
4
4
|
begin
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name
|
8
|
-
gem.summary
|
7
|
+
gem.name = 'mascut'
|
8
|
+
gem.summary = 'instant comet-like server in order to debug web pages'
|
9
9
|
gem.description = 'instant comet-like server in order to debug web pages'
|
10
|
-
gem.email
|
11
|
-
gem.homepage
|
12
|
-
gem.authors
|
10
|
+
gem.email = 'okitakunio@gmail.com'
|
11
|
+
gem.homepage = 'http://github.com/okitan/mascut'
|
12
|
+
gem.authors = %w[ okitan ]
|
13
13
|
|
14
|
-
gem.add_development_dependency '
|
14
|
+
gem.add_development_dependency 'rr', '>= 0.10.11'
|
15
|
+
gem.add_development_dependency 'rspec', '>= 1.3.0'
|
15
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
17
|
end
|
17
18
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/mascut/mascut.rb
CHANGED
@@ -16,11 +16,9 @@ module Mascut
|
|
16
16
|
body = [ File.read(body.path) ] if body.is_a?(Rack::File)
|
17
17
|
body.map! {|html| mascutize(html) }
|
18
18
|
headers['Content-Length'] = body.to_a.inject(0) { |len, part| len + Rack::Utils.bytesize(part) }.to_s
|
19
|
-
|
20
|
-
[ status, headers, [mascutize(body.first)] ]
|
21
|
-
else
|
22
|
-
[ status, headers, body ]
|
23
19
|
end
|
20
|
+
|
21
|
+
[ status, headers, body ]
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
@@ -39,7 +37,22 @@ module Mascut
|
|
39
37
|
|
40
38
|
def mascutize(html)
|
41
39
|
# I don't use html parser like nokogiri, because it corrects html to be debugged
|
42
|
-
html.sub('</head>', <<-
|
40
|
+
html.sub('</head>', @opts[:jquery] ? <<-LOCAL : <<-REMOTE)
|
41
|
+
<script src='#{@opts[:jquery]}'></script>
|
42
|
+
<script>
|
43
|
+
var comet = function() {
|
44
|
+
$.ajax({
|
45
|
+
type: 'GET',
|
46
|
+
url: '#{@path}',
|
47
|
+
success: function(msg) {
|
48
|
+
msg == 'reload' ? location.reload() : comet();
|
49
|
+
}
|
50
|
+
});
|
51
|
+
}
|
52
|
+
$(document).ready(comet);
|
53
|
+
</script>
|
54
|
+
</head>
|
55
|
+
LOCAL
|
43
56
|
<script src='http://www.google.com/jsapi'></script>
|
44
57
|
<script>
|
45
58
|
var comet = function() {
|
@@ -56,7 +69,7 @@ google.load('jquery', '1');
|
|
56
69
|
google.setOnLoadCallback(comet);
|
57
70
|
</script>
|
58
71
|
</head>
|
59
|
-
|
72
|
+
REMOTE
|
60
73
|
end
|
61
74
|
end
|
62
75
|
end
|
data/lib/mascut/option.rb
CHANGED
@@ -38,6 +38,10 @@ module Mascut
|
|
38
38
|
opts.on('-i', '--interval SEC', Float, 'interval to monitor files(default on Mascut::Mascut: 1.0 sec)') do |sec|
|
39
39
|
options[:interval] = sec
|
40
40
|
end
|
41
|
+
|
42
|
+
opts.on('-j', '--jquery JQUERY', 'jquery file to use for commet') do |file|
|
43
|
+
options[:jquery] = file
|
44
|
+
end
|
41
45
|
|
42
46
|
opts.permute!(args)
|
43
47
|
options[:files] = args.size > 0 ? args : nil
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[ .. spec_helper ])
|
2
|
+
|
3
|
+
describe Mascut::Mascut, '#new' do
|
4
|
+
context 'called with only an app' do
|
5
|
+
let(:app) { nil }
|
6
|
+
subject { Mascut::Mascut.new(app) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
# Dir.chdir(tmpdir)
|
10
|
+
# tmpdir has some files
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
# Dir.chdir(currentdir)
|
15
|
+
# delete tmpdir
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should assign @path with default value /mascut' do
|
19
|
+
subject.instance_variable_get(:@path).should == '/mascut'
|
20
|
+
end
|
21
|
+
|
22
|
+
it %(should assign @files with default value Dir['**/*']) do
|
23
|
+
pending 'I should change Dir to tmpdir'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should assign @opts with default value {}' do
|
27
|
+
subject.instance_variable_get(:@opts).should == {}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Mascut::Mascut, '#call' do
|
33
|
+
let(:app) { mock }
|
34
|
+
let(:files) { [ ] }
|
35
|
+
let(:middleware) { Mascut::Mascut.new(app, '/mascut', files, {}) }
|
36
|
+
|
37
|
+
subject { middleware.call('PATH_INFO' => path) }
|
38
|
+
|
39
|
+
let(:html) { '<html><head></head><body></body>' }
|
40
|
+
|
41
|
+
context 'if path is not mascut' do
|
42
|
+
let(:path) { '/hoge.html' }
|
43
|
+
let(:html) { '<html><head></head><body></body>' }
|
44
|
+
|
45
|
+
it 'app should be called' do
|
46
|
+
mock(app).call('PATH_INFO' => path)
|
47
|
+
subject
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'if app returns html with status 200' do
|
51
|
+
before do
|
52
|
+
stub(app).call { [ 200, { 'Content-Type' => 'text/html' }, [ html ] ] }
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should call mascutize' do
|
56
|
+
mock(middleware).mascutize(html) { 'mascutized' }
|
57
|
+
subject
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should also returns 200' do
|
61
|
+
subject[0].should == 200
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should add updated content length' do
|
65
|
+
stub(middleware).mascutize(html) { '12characters' }
|
66
|
+
subject[1].should include('Content-Length' => 12.to_s )
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should return mascutized values' do
|
70
|
+
mock(middleware).mascutize(html) { 'mascutized' }
|
71
|
+
subject[2].should == [ 'mascutized' ]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
[ [ 201, { 'Content-Type' => 'text/html' }, [ 'html' ] ],
|
76
|
+
[ 200, { 'Content-Type' => 'text/css' }, [ 'css' ] ],
|
77
|
+
].each do |response|
|
78
|
+
context "when status is #{response[0]} and Content-Type is #{response[1]['Content-Type']}" do
|
79
|
+
before do
|
80
|
+
stub(app).call { response }
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should return as is' do
|
84
|
+
subject.should == response
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'if path is mascut' do
|
91
|
+
let(:path) { '/mascut' }
|
92
|
+
it 'should wait until the files are updated' do
|
93
|
+
pending 'thread and benchmark'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe Mascut::Mascut, '#mascut' do
|
99
|
+
it 'should have specs'
|
100
|
+
end
|
101
|
+
|
102
|
+
describe Mascut::Mascut, '#mascutize' do
|
103
|
+
let(:app) { mock }
|
104
|
+
let(:html) { '<html><head></head><body></body>' }
|
105
|
+
subject { Mascut::Mascut.new(app, nil, nil, opts).mascutize(html) }
|
106
|
+
|
107
|
+
context 'if use local jquery' do
|
108
|
+
let(:jquery) { 'jquery_file' }
|
109
|
+
let(:opts) { { :jquery => jquery } }
|
110
|
+
|
111
|
+
it "should include local jquery path" do
|
112
|
+
subject.should =~ /#{jquery}/
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'if use remote jquery' do
|
117
|
+
let(:opts) { {} }
|
118
|
+
|
119
|
+
it 'should load jquery from google' do
|
120
|
+
subject.should =~ /http:\/\/www\.google\.com\/jsapi/
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[ .. spec_helper ])
|
2
|
+
|
3
|
+
describe Mascut::Option, '#parse' do
|
4
|
+
subject { Mascut::Option.parse(args) }
|
5
|
+
let(:value) { 'value' }
|
6
|
+
|
7
|
+
context 'String option' do
|
8
|
+
[ %w[ -s --server server ],
|
9
|
+
%w[ -o --host Host ],
|
10
|
+
%w[ -j --jquery jquery],
|
11
|
+
].each do |short, long, key|
|
12
|
+
context "with short option #{short}" do
|
13
|
+
let(:args) { [ short, value ] }
|
14
|
+
|
15
|
+
it "should assign #{key}" do
|
16
|
+
subject[key.to_sym].should == value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with long option #{long}" do
|
21
|
+
it 'should have specs'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context '-m --mascut' do
|
26
|
+
context 'with short option -m' do
|
27
|
+
it 'should assign mascut and add its head /' do
|
28
|
+
Mascut::Option.parse(%w[ -m mascut ])[:mascut].should == '/mascut'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should assign mascut and add its head /' do
|
32
|
+
Mascut::Option.parse(%w[ -m /mascut ])[:mascut].should == '/mascut'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with long option --mascut' do
|
37
|
+
it 'should have specs'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'Integer option' do
|
43
|
+
[ %w[ -p --port Port ],
|
44
|
+
].each do |short, long, key|
|
45
|
+
# XXX: now default value is Integer but parsed value is String
|
46
|
+
it 'should have specs'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'Float option' do
|
51
|
+
[ %w[ -i --interval interval],
|
52
|
+
].each do |short, long, key|
|
53
|
+
it 'should have specs'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# returns true/false
|
58
|
+
context 'boolean option' do
|
59
|
+
[
|
60
|
+
%w[ -D --daemonize daemonize],
|
61
|
+
].each do |short, long, key|
|
62
|
+
it 'should have specs'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# out of options
|
67
|
+
context 'not options' do
|
68
|
+
let(:args) { %w[ file1 file2 ] }
|
69
|
+
|
70
|
+
it 'should be assigned to files' do
|
71
|
+
subject[:files].should == args
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'invalid options' do
|
76
|
+
it 'should have specs'
|
77
|
+
end
|
78
|
+
|
79
|
+
# default values
|
80
|
+
[ [ :server, 'mongrel' ],
|
81
|
+
[ :Host, '0.0.0.0' ],
|
82
|
+
[ :Port, 9203 ],
|
83
|
+
[ :files, nil ],
|
84
|
+
].each do |key, default_value|
|
85
|
+
context "when #{key} is not specified" do
|
86
|
+
let(:args) { [] }
|
87
|
+
|
88
|
+
it 'should be assigned default value' do
|
89
|
+
subject[key].should == default_value
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
data/spec/mascut_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
require File.
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
it
|
5
|
-
fail "hey buddy, you should probably rename this file and start specing for real"
|
6
|
-
end
|
3
|
+
describe Mascut::VERSION do
|
4
|
+
it { should =~ /^\d+\.\d+\.\d+(\w+)?$/ }
|
7
5
|
end
|
6
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
1
|
+
$: << File.join(File.dirname(__FILE__), %w[ .. lib ])
|
3
2
|
require 'mascut'
|
4
|
-
|
5
|
-
require '
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rack'
|
6
|
+
require 'rr'
|
6
7
|
|
7
8
|
Spec::Runner.configure do |config|
|
8
|
-
|
9
|
+
config.mock_with :rr
|
9
10
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- okitan
|
@@ -14,23 +14,37 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-24 00:00:00 +09:00
|
18
18
|
default_executable: mascut
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: rr
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
version:
|
28
|
+
- 0
|
29
|
+
- 10
|
30
|
+
- 11
|
31
|
+
version: 0.10.11
|
32
32
|
type: :development
|
33
33
|
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 3
|
44
|
+
- 0
|
45
|
+
version: 1.3.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
34
48
|
description: instant comet-like server in order to debug web pages
|
35
49
|
email: okitakunio@gmail.com
|
36
50
|
executables:
|
@@ -52,6 +66,8 @@ files:
|
|
52
66
|
- lib/mascut.rb
|
53
67
|
- lib/mascut/mascut.rb
|
54
68
|
- lib/mascut/option.rb
|
69
|
+
- spec/mascut/mascut_spec.rb
|
70
|
+
- spec/mascut/option_spec.rb
|
55
71
|
- spec/mascut_spec.rb
|
56
72
|
- spec/spec.opts
|
57
73
|
- spec/spec_helper.rb
|
@@ -86,5 +102,7 @@ signing_key:
|
|
86
102
|
specification_version: 3
|
87
103
|
summary: instant comet-like server in order to debug web pages
|
88
104
|
test_files:
|
105
|
+
- spec/mascut/mascut_spec.rb
|
106
|
+
- spec/mascut/option_spec.rb
|
89
107
|
- spec/spec_helper.rb
|
90
108
|
- spec/mascut_spec.rb
|