otherinbox-capybara-webkit 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +2 -0
  3. data/Appraisals +7 -0
  4. data/CONTRIBUTING.md +47 -0
  5. data/ChangeLog +70 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +68 -0
  8. data/LICENSE +19 -0
  9. data/NEWS.md +36 -0
  10. data/README.md +114 -0
  11. data/Rakefile +65 -0
  12. data/bin/Info.plist +22 -0
  13. data/capybara-webkit.gemspec +28 -0
  14. data/extconf.rb +2 -0
  15. data/gemfiles/1.0.gemfile +7 -0
  16. data/gemfiles/1.0.gemfile.lock +70 -0
  17. data/gemfiles/1.1.gemfile +7 -0
  18. data/gemfiles/1.1.gemfile.lock +70 -0
  19. data/lib/capybara-webkit.rb +1 -0
  20. data/lib/capybara/driver/webkit.rb +135 -0
  21. data/lib/capybara/driver/webkit/browser.rb +168 -0
  22. data/lib/capybara/driver/webkit/connection.rb +120 -0
  23. data/lib/capybara/driver/webkit/cookie_jar.rb +55 -0
  24. data/lib/capybara/driver/webkit/node.rb +118 -0
  25. data/lib/capybara/driver/webkit/socket_debugger.rb +43 -0
  26. data/lib/capybara/driver/webkit/version.rb +7 -0
  27. data/lib/capybara/webkit.rb +11 -0
  28. data/lib/capybara/webkit/matchers.rb +37 -0
  29. data/lib/capybara_webkit_builder.rb +68 -0
  30. data/spec/browser_spec.rb +248 -0
  31. data/spec/capybara_webkit_builder_spec.rb +37 -0
  32. data/spec/connection_spec.rb +54 -0
  33. data/spec/cookie_jar_spec.rb +48 -0
  34. data/spec/driver_rendering_spec.rb +80 -0
  35. data/spec/driver_resize_window_spec.rb +59 -0
  36. data/spec/driver_spec.rb +1552 -0
  37. data/spec/integration/driver_spec.rb +20 -0
  38. data/spec/integration/session_spec.rb +137 -0
  39. data/spec/self_signed_ssl_cert.rb +42 -0
  40. data/spec/spec_helper.rb +46 -0
  41. data/src/Body.h +12 -0
  42. data/src/ClearCookies.cpp +15 -0
  43. data/src/ClearCookies.h +11 -0
  44. data/src/Command.cpp +19 -0
  45. data/src/Command.h +31 -0
  46. data/src/CommandFactory.cpp +38 -0
  47. data/src/CommandFactory.h +16 -0
  48. data/src/CommandParser.cpp +76 -0
  49. data/src/CommandParser.h +33 -0
  50. data/src/Connection.cpp +71 -0
  51. data/src/Connection.h +37 -0
  52. data/src/ConsoleMessages.cpp +10 -0
  53. data/src/ConsoleMessages.h +12 -0
  54. data/src/CurrentUrl.cpp +68 -0
  55. data/src/CurrentUrl.h +16 -0
  56. data/src/Evaluate.cpp +84 -0
  57. data/src/Evaluate.h +22 -0
  58. data/src/Execute.cpp +16 -0
  59. data/src/Execute.h +12 -0
  60. data/src/Find.cpp +19 -0
  61. data/src/Find.h +13 -0
  62. data/src/FrameFocus.cpp +66 -0
  63. data/src/FrameFocus.h +28 -0
  64. data/src/GetCookies.cpp +20 -0
  65. data/src/GetCookies.h +14 -0
  66. data/src/Header.cpp +18 -0
  67. data/src/Header.h +11 -0
  68. data/src/Headers.cpp +10 -0
  69. data/src/Headers.h +12 -0
  70. data/src/IgnoreSslErrors.cpp +12 -0
  71. data/src/IgnoreSslErrors.h +12 -0
  72. data/src/JavascriptInvocation.cpp +14 -0
  73. data/src/JavascriptInvocation.h +19 -0
  74. data/src/NetworkAccessManager.cpp +29 -0
  75. data/src/NetworkAccessManager.h +19 -0
  76. data/src/NetworkCookieJar.cpp +101 -0
  77. data/src/NetworkCookieJar.h +15 -0
  78. data/src/Node.cpp +14 -0
  79. data/src/Node.h +13 -0
  80. data/src/NullCommand.cpp +10 -0
  81. data/src/NullCommand.h +11 -0
  82. data/src/PageLoadingCommand.cpp +46 -0
  83. data/src/PageLoadingCommand.h +40 -0
  84. data/src/Render.cpp +18 -0
  85. data/src/Render.h +12 -0
  86. data/src/RequestedUrl.cpp +12 -0
  87. data/src/RequestedUrl.h +12 -0
  88. data/src/Reset.cpp +29 -0
  89. data/src/Reset.h +15 -0
  90. data/src/ResizeWindow.cpp +16 -0
  91. data/src/ResizeWindow.h +12 -0
  92. data/src/Response.cpp +24 -0
  93. data/src/Response.h +15 -0
  94. data/src/Server.cpp +24 -0
  95. data/src/Server.h +21 -0
  96. data/src/SetCookie.cpp +16 -0
  97. data/src/SetCookie.h +11 -0
  98. data/src/SetProxy.cpp +22 -0
  99. data/src/SetProxy.h +11 -0
  100. data/src/SetSkipImageLoading.cpp +11 -0
  101. data/src/SetSkipImageLoading.h +11 -0
  102. data/src/Source.cpp +18 -0
  103. data/src/Source.h +19 -0
  104. data/src/Status.cpp +12 -0
  105. data/src/Status.h +12 -0
  106. data/src/UnsupportedContentHandler.cpp +32 -0
  107. data/src/UnsupportedContentHandler.h +18 -0
  108. data/src/Url.cpp +12 -0
  109. data/src/Url.h +12 -0
  110. data/src/Visit.cpp +12 -0
  111. data/src/Visit.h +12 -0
  112. data/src/WebPage.cpp +246 -0
  113. data/src/WebPage.h +58 -0
  114. data/src/body.cpp +10 -0
  115. data/src/capybara.js +315 -0
  116. data/src/find_command.h +30 -0
  117. data/src/main.cpp +31 -0
  118. data/src/webkit_server.pro +87 -0
  119. data/src/webkit_server.qrc +5 -0
  120. data/templates/Command.cpp +10 -0
  121. data/templates/Command.h +12 -0
  122. data/webkit_server.pro +4 -0
  123. metadata +300 -0
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.swp
2
+ bin/webkit_server*
3
+ *.swo
4
+ *~
5
+ *.o
6
+ *.moc
7
+ Makefile*
8
+ qrc_*
9
+ *.xcodeproj
10
+ *.app
11
+ moc_*.cpp
12
+ .bundle
13
+ pkg
14
+ src/webkit_server
15
+ src/webkit_server.exe
16
+ .DS_Store
17
+ tmp
18
+ .rvmrc
19
+ src/debug
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise "1.0" do
2
+ gem "capybara", "~> 1.0.0"
3
+ end
4
+
5
+ appraise "1.1" do
6
+ gem "capybara", "~> 1.1.0"
7
+ end
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,47 @@
1
+ We love pull requests. Here's a quick guide:
2
+
3
+ Dependencies
4
+
5
+ Some of the tests depend on the `identify` command that comes with Imagemagick.
6
+ Imagemagick can be installed via [homebrew](http://mxcl.github.com/homebrew/).
7
+
8
+ brew install imagemagick
9
+
10
+ Contributing
11
+
12
+ 1. Fork the repo.
13
+
14
+ 2. Run the tests. We only take pull requests with passing tests, and it's great
15
+ to know that you have a clean slate: `bundle && bundle exec rake`
16
+
17
+ 3. Add a test for your change. Only refactoring and documentation changes
18
+ require no new tests. If you are adding functionality or fixing a bug, we need
19
+ a test!
20
+
21
+ 4. Make the test pass.
22
+
23
+ 5. Push to your fork and submit a pull request.
24
+
25
+
26
+ At this point you're waiting on us. We like to at least comment on, if not
27
+ accept, pull requests within three business days (and, typically, one business
28
+ day). We may suggest some changes or improvements or alternatives.
29
+
30
+ Some things that will increase the chance that your pull request is accepted,
31
+ taken straight from the Ruby on Rails guide:
32
+
33
+ * Use Rails idioms and helpers
34
+ * Include tests that fail without your code, and pass with it
35
+ * Update the documentation, the surrounding one, examples elsewhere, guides,
36
+ whatever is affected by your contribution
37
+
38
+ Syntax:
39
+
40
+ * Two spaces, no tabs.
41
+ * No trailing whitespace. Blank lines should not have any space.
42
+ * Prefer &&/|| over and/or.
43
+ * MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
44
+ * a = b and not a=b.
45
+ * Follow the conventions you see used in the source already.
46
+
47
+ And in case we didn't emphasize it enough: we love tests!
data/ChangeLog ADDED
@@ -0,0 +1,70 @@
1
+ 2012-03-09 Joe Ferris <jferris@thoughtbot.com>
2
+ * node.rb, driver_spec.rb: Allow interaction with invisible elements
3
+
4
+ 2012-03-02 Joe Ferris <jferris@thoughtbot.com>
5
+ * browser.rb: Use Timeout from stdlib since Capybara.timeout is being removed
6
+
7
+ 2012-03-02 Matthew Mongeau <halogenandtoast@gmail.com>
8
+ * capybara_webkit_builder.rb:
9
+ set LANG to en_US.UTF-8 to prevent string encoding issues during install
10
+
11
+ 2012-03-02 Marc Schwieterman
12
+ * Rakefile: pro, find_command, and CommandFactory are more structured
13
+
14
+ 2012-02-27 Joe Ferris <jferris@thoughtbot.com>
15
+ * README.md: Fixed broken wiki link
16
+
17
+ 2012-02-24 Joe Ferris <jferris@thoughtbot.com>
18
+ * README.md: Update instructions for platform specific installation issues
19
+
20
+ 2012-02-17 Matthew Mongeau <halogenandtoast@gmail.com>
21
+ * driver_spec.rb, capybara.js: Send proper keycode during keypress event
22
+
23
+ 2012-02-17 Matthew Mongeau <halogenandtoast@gmail.com>
24
+ * ChangeLog, version.rb:
25
+ Bump to 0.10.0
26
+
27
+ 2012-02-17 Marc Schwieterman
28
+ * driver_spec.rb, Reset.cpp, Reset.h: Reset history when resetting session.
29
+ * driver_spec.rb, webkit.rb, browser.rb, CommandFactory.cpp, CurrentUrl.cpp,
30
+ CurrentUrl.h, find_command.h, webkit_server.pro:
31
+ current_url now conforms more closely to the behavior of Selenium.
32
+
33
+ 2012-02-17 Igor Zubkov <igor.zubkov@gmail.com>
34
+ * spec_helper.rb: Fix typo.
35
+
36
+ 2012-02-17 Matthew Mongeau <halogenandtoast@gmail.com>
37
+ * capybara_webkit_builder.rb, capybara_webkit_builder_spec.rb,
38
+ spec_helper.rb:
39
+ Allow for overriding MAKE, QMAKE, and SPEC options via the environment.
40
+
41
+ 2012-02-12 Jason Petersen <jasonmp85@gmail.com>
42
+ * driver_spec.rb, node.rb, capybara.js:
43
+ Selected attribute is no longer removed when selecting/deselecting. Only the
44
+ property is changed.
45
+
46
+ 2012-02-09 Gabe Berke-Williams <gabe@thoughtbot.com>
47
+ * capybara-webkit.gemspec: Note capybara-webkit's usage of Sinatra.
48
+
49
+ 2012-02-03 Matthew Mongeau <halogenandtoast@gmail.com>
50
+ * version.rb:
51
+ Bump to 0.9.0
52
+
53
+ 2012-02-01 Joe Ferris <jferris@thoughtbot.com>
54
+ * driver_spec.rb, Connection.cpp, Connection.h:
55
+ Try to detect when a command starts a page load and wait for it to finish.
56
+
57
+ 2012-01-27 Matthew Mongeau <halogenandtoast@gmail.com>
58
+ * driver_spec.rb, capybara.js: Trigger mousedown and mouseup events.
59
+ * driver_spec.rb, capybara.js: Simulate browser events more closely.
60
+
61
+ 2012-01-19 Marco Antonio <marcofognog@gmail.com>
62
+ * node.rb, driver_spec.rb:
63
+ Raise ElementNotDisplayedError also for #drag_to and #select_option when they are invisible.
64
+
65
+ 2012-01-18 Marco Antonio <marcofognog@gmail.com>
66
+ * node.rb, driver_spec.rb:
67
+ Raise error when an invisible element receives #click so it resembles a browser more closely.
68
+
69
+ 2012-01-15 Marc Schwieterman
70
+ * CONTRIBUTING.md: add imagemagick dependency to contributing guide.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capybara-webkit (0.12.0)
5
+ capybara (>= 1.0.0, < 1.2)
6
+ json
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ appraisal (0.4.0)
12
+ bundler
13
+ rake
14
+ capybara (1.1.2)
15
+ mime-types (>= 1.16)
16
+ nokogiri (>= 1.3.3)
17
+ rack (>= 1.0.0)
18
+ rack-test (>= 0.5.4)
19
+ selenium-webdriver (~> 2.0)
20
+ xpath (~> 0.1.4)
21
+ childprocess (0.3.1)
22
+ ffi (~> 1.0.6)
23
+ diff-lcs (1.1.2)
24
+ ffi (1.0.11)
25
+ json (1.7.1)
26
+ mime-types (1.18)
27
+ mini_magick (3.2.1)
28
+ subexec (~> 0.0.4)
29
+ multi_json (1.0.4)
30
+ nokogiri (1.5.0)
31
+ nokogiri (1.5.0-x86-mingw32)
32
+ rack (1.3.2)
33
+ rack-test (0.6.1)
34
+ rack (>= 1.0)
35
+ rake (0.9.2)
36
+ rspec (2.6.0)
37
+ rspec-core (~> 2.6.0)
38
+ rspec-expectations (~> 2.6.0)
39
+ rspec-mocks (~> 2.6.0)
40
+ rspec-core (2.6.4)
41
+ rspec-expectations (2.6.0)
42
+ diff-lcs (~> 1.1.2)
43
+ rspec-mocks (2.6.0)
44
+ rubyzip (0.9.7)
45
+ selenium-webdriver (2.19.0)
46
+ childprocess (>= 0.2.5)
47
+ ffi (~> 1.0.9)
48
+ multi_json (~> 1.0.4)
49
+ rubyzip
50
+ sinatra (1.1.2)
51
+ rack (~> 1.1)
52
+ tilt (~> 1.2)
53
+ subexec (0.0.4)
54
+ tilt (1.2.2)
55
+ xpath (0.1.4)
56
+ nokogiri (~> 1.3)
57
+
58
+ PLATFORMS
59
+ ruby
60
+ x86-mingw32
61
+
62
+ DEPENDENCIES
63
+ appraisal (~> 0.4.0)
64
+ capybara-webkit!
65
+ mini_magick
66
+ rake
67
+ rspec (~> 2.6.0)
68
+ sinatra
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 thoughtbot, inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/NEWS.md ADDED
@@ -0,0 +1,36 @@
1
+ New for 0.12.0:
2
+ * Better windows support
3
+ * Support for localStorage
4
+ * Added support for oninput event
5
+ * Added resize_window method
6
+ * Server binds on LocalHost to prevent having to add firewall exceptions
7
+ * Reuse NetworkAccessManager to prevent "too many open files" errors
8
+ * Response messages are stored as QByteArray to prevent truncating content
9
+ * Browser no longer tries to read empty responses (Fixes jruby issues).
10
+ * Server will timeout if it can not start
11
+
12
+ New for 0.11.0:
13
+
14
+ * Allow interaction with invisible elements
15
+ * Use Timeout from stdlib since Capybara.timeout is being removed
16
+
17
+ New for 0.10.1:
18
+
19
+ * LANG environment variable is set to en_US.UTF-8 in order to avoid string encoding issues from qmake.
20
+ * pro, find_command, and CommandFactory are more structured.
21
+ * Changed wiki link and directing platform specific issues to the google group.
22
+ * Pass proper keycode value for keypress events.
23
+
24
+ New for 0.10.0:
25
+
26
+ * current_url now more closely matches the behavior of Selenium
27
+ * custom MAKE, QMAKE, and SPEC options can be set from the environment
28
+ * BUG: Selected attribute is no longer removed when selecting/deselecting. Only the property is changed.
29
+
30
+ New for 0.9.0:
31
+
32
+ * Raise an error when an invisible element receives #click.
33
+ * Raise ElementNotDisplayedError for #drag_to and #select_option when element is invisible.
34
+ * Trigger mousedown and mouseup events.
35
+ * Model mouse events more closely to the browser.
36
+ * Try to detech when a command starts a page load and wait for it to finish
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ capybara-webkit
2
+ ===============
3
+
4
+ A [capybara](https://github.com/jnicklas/capybara) driver that uses [WebKit](http://webkit.org) via [QtWebKit](http://doc.qt.nokia.com/4.7/qtwebkit.html).
5
+
6
+ Qt Dependency and Installation Issues
7
+ -------------
8
+
9
+ capybara-webkit depends on a WebKit implementation from Qt, a cross-platform
10
+ development toolkit. You'll need to download the Qt libraries to build and
11
+ install the gem. You can find instructions for downloading and installing QT on
12
+ the [capybara-webkit wiki](https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit)
13
+
14
+ Windows Support
15
+ ---------------
16
+
17
+ Currently 32bit Windows will compile Capybara-webkit. Support for Windows is provided by the open source community and Windows related issues should be posted to the [mailing list](http://groups.google.com/group/capybara-webkit)
18
+
19
+ Reporting Issues
20
+ ----------------
21
+
22
+ Without access to your application code we can't easily debug most crashes or
23
+ generic failures, so we've included a debug version of the driver that prints a
24
+ log of what happened during each test. Before filing a crash bug, please see
25
+ [Reporting Crashes](https://github.com/thoughtbot/capybara-webkit/wiki/Reporting-Crashes).
26
+ You're much more likely to get a fix if you follow those instructions.
27
+
28
+ If you are having compiling issues please check out the
29
+ [capybara-webkit wiki](https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit).
30
+ If you don't have any luck there, please post to the
31
+ [mailing list](http://groups.google.com/group/capybara-webkit). Please don't
32
+ open a Github issue for a system-specific compiler issue.
33
+
34
+ CI
35
+ --
36
+
37
+ If you're like us, you'll be using capybara-webkit on CI.
38
+
39
+ On Linux platforms, capybara-webkit requires an X server to run, although it doesn't create any visible windows. Xvfb works fine for this. You can setup Xvfb yourself and set a DISPLAY variable, or try out the [headless gem](https://github.com/leonid-shevtsov/headless).
40
+
41
+ Usage
42
+ -----
43
+
44
+ Add the capybara-webkit gem to your Gemfile:
45
+
46
+ gem "capybara-webkit"
47
+
48
+ Set your Capybara Javascript driver to webkit:
49
+
50
+ Capybara.javascript_driver = :webkit
51
+
52
+ In cucumber, tag scenarios with @javascript to run them using a headless WebKit browser.
53
+
54
+ In RSpec, use the :js => true flag.
55
+
56
+ Take note of the transactional fixtures section of the [capybara README](https://github.com/jnicklas/capybara/blob/master/README.md).
57
+
58
+ If you're using capybara-webkit with Sinatra, don't forget to set
59
+
60
+ Capybara.app = MySinatraApp.new
61
+
62
+ Non-Standard Driver Methods
63
+ ---------------------------
64
+
65
+ capybara-webkit supports a few methods that are not part of the standard capybara API. You can access these by calling `driver` on the capybara session. When using the DSL, that will look like `page.driver.method_name`.
66
+
67
+ **console_messages**: returns an array of messages printed using console.log
68
+
69
+ # In Javascript:
70
+ console.log("hello")
71
+ # In Ruby:
72
+ page.driver.console_messages
73
+ => {:source=>"http://example.com", :line_number=>1, :message=>"hello"}
74
+
75
+ **error_messages**: returns an array of Javascript errors that occurred
76
+
77
+ page.driver.error_messages
78
+ => {:source=>"http://example.com", :line_number=>1, :message=>"SyntaxError: Parse error"}
79
+
80
+ **resize_window**: change the viewport size to the given width and height
81
+
82
+ page.driver.resize_window(500, 300)
83
+ page.driver.evaluate_script("window.innerWidth")
84
+ => 500
85
+
86
+ **render**: render a screenshot of the current view (requires [mini_magick](https://github.com/probablycorey/mini_magick) and [ImageMagick](http://www.imagemagick.org))
87
+
88
+ page.driver.render "tmp/screenshot.png"
89
+
90
+ **cookies**: allows read-only access of cookies for the current session
91
+
92
+ page.driver.cookies["alpha"]
93
+ => "abc"
94
+
95
+ Contributing
96
+ ------------
97
+
98
+ See the CONTRIBUTING document.
99
+
100
+ About
101
+ -----
102
+
103
+ The capybara WebKit driver is maintained by Joe Ferris and Matt Mongeau. It was written by [thoughtbot, inc](http://thoughtbot.com/community) with the help of numerous [contributions from the open source community](https://github.com/thoughtbot/capybara-webkit/contributors).
104
+
105
+ Code for rendering the current webpage to a PNG is borrowed from Phantom.js' implementation.
106
+
107
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
108
+
109
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
110
+
111
+ License
112
+ -------
113
+
114
+ capybara-webkit is Copyright (c) 2011 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,65 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+ require 'capybara_webkit_builder'
4
+ require 'appraisal'
5
+
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ desc "Generate a Makefile using qmake"
9
+ file 'Makefile' do
10
+ CapybaraWebkitBuilder.makefile or exit(1)
11
+ end
12
+
13
+ desc "Regenerate dependencies using qmake"
14
+ task :qmake => 'Makefile' do
15
+ CapybaraWebkitBuilder.qmake or exit(1)
16
+ end
17
+
18
+ desc "Build the webkit server"
19
+ task :build => :qmake do
20
+ CapybaraWebkitBuilder.build or exit(1)
21
+ end
22
+
23
+ file 'bin/webkit_server' => :build
24
+
25
+ RSpec::Core::RakeTask.new do |t|
26
+ t.pattern = "spec/**/*_spec.rb"
27
+ t.rspec_opts = "--format progress"
28
+ end
29
+
30
+ desc "Default: build and run all specs"
31
+ task :default => [:build, :spec]
32
+
33
+ desc "Generate a new command called NAME"
34
+ task :generate_command do
35
+ name = ENV['NAME'] or raise "Provide a name with NAME="
36
+
37
+ header = "src/#{name}.h"
38
+ source = "src/#{name}.cpp"
39
+
40
+ %w(h cpp).each do |extension|
41
+ File.open("templates/Command.#{extension}", "r") do |source_file|
42
+ contents = source_file.read
43
+ contents.gsub!("NAME", name)
44
+ File.open("src/#{name}.#{extension}", "w") do |target_file|
45
+ target_file.write(contents)
46
+ end
47
+ end
48
+ end
49
+
50
+ Dir.glob("src/*.pro").each do |project_file_name|
51
+ project = IO.read(project_file_name)
52
+ project.gsub!(/^(HEADERS = .*)/, "\\1\n #{name}.h \\")
53
+ project.gsub!(/^(SOURCES = .*)/, "\\1\n #{name}.cpp \\")
54
+ File.open(project_file_name, "w") { |file| file.write(project) }
55
+ end
56
+
57
+ File.open("src/find_command.h", "a") do |file|
58
+ file.write("CHECK_COMMAND(#{name})\n")
59
+ end
60
+
61
+ command_factory_file_name = "src/CommandFactory.cpp"
62
+ command_factory = IO.read(command_factory_file_name)
63
+ command_factory.sub!(/^$/, "#include \"#{name}.h\"\n")
64
+ File.open(command_factory_file_name, "w") { |file| file.write(command_factory) }
65
+ end