masque 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -51,7 +51,6 @@ more examples are available in examples/ directory.
51
51
 
52
52
  - Impl useful DSL
53
53
  - Respect driver specific features/options
54
- - Add support Selenium driver
55
54
 
56
55
 
57
56
  ## Contributing
@@ -0,0 +1,36 @@
1
+ # -- coding: utf-8
2
+
3
+ =begin
4
+ Usage: ./responsive_webdesign_check.rb [TargetURL]
5
+
6
+ $ ruby ./responsive_webdesign_check.rb "http://www.nhk.or.jp/studiopark/"
7
+ 640x480 rendering..
8
+ 800x600 rendering..
9
+ 1024x768 rendering..
10
+ 1280x960 rendering..
11
+ 1280x1024 rendering..
12
+
13
+ will save as "screenshots_by_masque/#{size}.png"
14
+ See example result: http://imgur.com/a/1MgeF
15
+ =end
16
+
17
+ require "fileutils"
18
+ require File.expand_path("../../lib/masque.rb", __FILE__)
19
+
20
+ url = ARGV.first || "http://www.nhk.or.jp/studiopark/"
21
+ dir = "screenshots_by_masque"
22
+ FileUtils.mkdir(dir) unless File.directory?(dir)
23
+
24
+ Masque.run(:driver => :poltergeist) do # webkit always render as full height
25
+ visit url
26
+
27
+ %W!640x480 800x600 1024x768 1280x960 1280x1024!.each do |size|
28
+ puts "#{size} rendering.."
29
+ width, height = *size.split("x").map(&:to_i)
30
+ resize width, height
31
+ sleep 1 # wait animation finish
32
+ render "#{dir}/#{size}.png"
33
+ resize width, evaluate_script("document.body.scrollHeight")
34
+ render "#{dir}/#{size}-full.png"
35
+ end
36
+ end
data/lib/masque.rb CHANGED
@@ -25,8 +25,12 @@ class Masque
25
25
  @session = session
26
26
  end
27
27
 
28
- def method_missing(*args)
29
- session.__send__(*args)
28
+ def method_missing(*args, &block)
29
+ if block_given?
30
+ session.__send__(*args, &block)
31
+ else
32
+ session.__send__(*args)
33
+ end
30
34
  end
31
35
  end.new(Capybara::Session.new(@driver))
32
36
 
@@ -1,3 +1,3 @@
1
1
  class Masque
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,12 @@
1
+ # -- coding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Masque do
6
+ let(:driver) { :poltergeist }
7
+
8
+ context "poltergeist" do
9
+ it_behaves_like "driver"
10
+ end
11
+ end
12
+
data/spec/masque_spec.rb CHANGED
@@ -3,103 +3,11 @@
3
3
  require "spec_helper"
4
4
 
5
5
  describe Masque do
6
- [:webkit, :poltergeist].each do |driver|
7
- context "Using #{driver} driver" do
8
- let(:driver) { driver }
9
- let!(:masque) do
10
- m = Masque.new(:driver => driver)
11
- m.agent.session = Capybara::Session.new(driver, Dummy)
12
- m
13
- end
14
-
15
- it ".new" do
16
- opts = {:display => 50, :driver => driver}
17
- masque = Masque.new(opts)
18
- masque.options.should == opts
19
- masque.respond_to?(:run).should be_true
20
- end
21
-
22
- describe ".run" do
23
- it "Capybara::DSL ready" do
24
- mods = []
25
- title = nil
26
- masque.run do
27
- mods = self.class.included_modules
28
- visit "/dummy"
29
- title = evaluate_script "document.title"
30
- end
31
- title["dummy"].should_not be_nil
32
- end
33
-
34
- it "#save_screenshot" do
35
- path = "spec/tmp.png"
36
- masque.run do
37
- visit "/"
38
- render(path)
39
- end
40
- File.file?(path).should be_true
41
- File.size(path).should be > 0
42
- File.unlink(path)
43
- end
44
-
45
- it "#cookies" do
46
- cookie = masque.run do
47
- visit "/"
48
- cookies["rack.session"]
49
- end
50
- cookie.should_not be_nil
51
- end
52
-
53
- it "#set_headers" do
54
- masque.run do
55
- set_headers({"User-Agent" => "rspec"})
56
- visit "/"
57
- find('#ua').text.should == "rspec"
58
- end
59
- end
60
-
61
- it "#resize" do
62
- masque.run do
63
- resize(400, 300)
64
- visit "/"
65
- size = MultiJson.load(find('#js').text)
66
- size["w"].should == 400
67
- size["h"].should == 300
68
- end
69
- end
70
-
71
- it "return last evaluated value" do
72
- body = masque.run do
73
- visit "/"
74
- page.body
75
- end
76
- body.should_not be_nil
77
- end
78
- end
79
-
80
- it "#reset_session!" do
81
- first, second, third = nil
82
-
83
- masque.run do
84
- visit "/"
85
- first = find('h1').text.to_i
86
- end
87
- masque.run do
88
- visit "/"
89
- second = find('h1').text.to_i
90
- end
91
-
92
- masque.reset_session!
93
- masque.run do
94
- visit "/"
95
- third = find('h1').text.to_i
96
- end
97
-
98
- first.should == 1
99
- second.should == 2
100
- third.should == 1
101
- end
102
- end
6
+ it ".new" do
7
+ opts = {:display => 50, :driver => :webkit}
8
+ masque = Masque.new(opts)
9
+ masque.options.should == opts
10
+ masque.respond_to?(:run).should be_true
103
11
  end
104
12
  end
105
13
 
@@ -0,0 +1,12 @@
1
+ # -- coding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Masque do
6
+ let(:driver) { :webkit }
7
+
8
+ context "webkit" do
9
+ it_behaves_like "driver"
10
+ end
11
+ end
12
+
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,7 @@ require "pp"
4
4
  require "rubygems"
5
5
  require "rspec-expectations"
6
6
  require "rspec/matchers/built_in/be"
7
- require File.expand_path("../support/app.rb", __FILE__)
7
+ Dir["./spec/support/**/*.rb"].each{|file| require file }
8
8
 
9
9
  if ENV["COVERAGE"]
10
10
  require "simplecov"
data/spec/support/app.rb CHANGED
@@ -21,12 +21,21 @@ class Dummy < Sinatra::Base
21
21
  <div id="ua">#{env["HTTP_USER_AGENT"]}</div>
22
22
  <p>Hello, World!</p>
23
23
  <div id="js"></div>
24
+ <div id="params">#{MultiJson.dump(params)}</div>
24
25
  <script>
25
26
  document.getElementById("js").innerHTML = JSON.stringify({
26
27
  h: window.innerHeight,
27
28
  w: window.innerWidth
28
29
  });
29
30
  </script>
31
+ <form id="form" action="/">
32
+ <input type="text" name="a" />
33
+ <select name="b">
34
+ <option value="1">1</option>
35
+ <option value="2">2</option>
36
+ </select>
37
+ <input type="submit" />
38
+ </form>
30
39
  HTML
31
40
  end
32
41
  end
@@ -0,0 +1,95 @@
1
+ # -- coding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ shared_examples_for "driver" do
6
+ let!(:masque) do
7
+ m = Masque.new(:driver => driver)
8
+ m.agent.session = Capybara::Session.new(driver, Dummy)
9
+ m
10
+ end
11
+
12
+ describe ".run" do
13
+ it "Capybara::DSL ready" do
14
+ mods = []
15
+ title = nil
16
+ masque.run do
17
+ visit "/dummy"
18
+ title = evaluate_script "document.title"
19
+ within("#form") do
20
+ fill_in "a", :with => "A"
21
+ end
22
+ find('input[type="submit"]').click
23
+ end
24
+ title["dummy"].should_not be_nil
25
+ end
26
+
27
+ it "#save_screenshot" do
28
+ path = "spec/tmp.png"
29
+ masque.run do
30
+ visit "/"
31
+ render(path)
32
+ end
33
+ File.file?(path).should be_true
34
+ File.size(path).should be > 0
35
+ File.unlink(path)
36
+ end
37
+
38
+ it "#cookies" do
39
+ cookie = masque.run do
40
+ visit "/"
41
+ cookies["rack.session"]
42
+ end
43
+ cookie.should_not be_nil
44
+ end
45
+
46
+ it "#set_headers" do
47
+ masque.run do
48
+ set_headers({"User-Agent" => "rspec"})
49
+ visit "/"
50
+ find('#ua').text.should == "rspec"
51
+ end
52
+ end
53
+
54
+ it "#resize" do
55
+ masque.run do
56
+ resize(400, 300)
57
+ visit "/"
58
+ size = MultiJson.load(find('#js').text)
59
+ size["w"].should == 400
60
+ size["h"].should == 300
61
+ end
62
+ end
63
+
64
+ it "return last evaluated value" do
65
+ body = masque.run do
66
+ visit "/"
67
+ page.body
68
+ end
69
+ body.should_not be_nil
70
+ end
71
+ end
72
+
73
+ it "#reset_session!" do
74
+ first, second, third = nil
75
+
76
+ masque.run do
77
+ visit "/"
78
+ first = find('h1').text.to_i
79
+ end
80
+ masque.run do
81
+ visit "/"
82
+ second = find('h1').text.to_i
83
+ end
84
+
85
+ masque.reset_session!
86
+ masque.run do
87
+ visit "/"
88
+ third = find('h1').text.to_i
89
+ end
90
+
91
+ first.should == 1
92
+ second.should == 2
93
+ third.should == 1
94
+ end
95
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: masque
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-21 00:00:00.000000000 Z
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -151,14 +151,18 @@ files:
151
151
  - LICENSE.txt
152
152
  - README.md
153
153
  - Rakefile
154
+ - examples/responsive_webdesign_check.rb
154
155
  - examples/text_from_image.rb
155
156
  - lib/masque.rb
156
157
  - lib/masque/dsl.rb
157
158
  - lib/masque/version.rb
158
159
  - masque.gemspec
160
+ - spec/masque_poltergeist_spec.rb
159
161
  - spec/masque_spec.rb
162
+ - spec/masque_webkit_spec.rb
160
163
  - spec/spec_helper.rb
161
164
  - spec/support/app.rb
165
+ - spec/support/driver.rb
162
166
  homepage: ''
163
167
  licenses: []
164
168
  post_install_message:
@@ -184,7 +188,10 @@ signing_key:
184
188
  specification_version: 3
185
189
  summary: JavaScript enabled web crawler kit
186
190
  test_files:
191
+ - spec/masque_poltergeist_spec.rb
187
192
  - spec/masque_spec.rb
193
+ - spec/masque_webkit_spec.rb
188
194
  - spec/spec_helper.rb
189
195
  - spec/support/app.rb
196
+ - spec/support/driver.rb
190
197
  has_rdoc: