capybara-envjs-fixes 0.0.3

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 ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jason Morrison
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.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ = capybara-envjs-fixes
2
+
3
+ Fixes on top of capybara-envjs.
4
+
5
+ == Rails 3 usage
6
+
7
+ Include the git repository in your Gemfile:
8
+
9
+ gem 'capybara-envjs-fixes', :git => "git://github.com/thoughtbot/capybara-envjs-fixes.git"
10
+
11
+ Then, require the fixes from within cucumber:
12
+
13
+ $ cat features/support/capybara_envjs_fixes.rb
14
+ require 'capybara_envjs_fixes/cucumber_fixes'
15
+
16
+ == Note on Patches/Pull Requests
17
+
18
+ * Fork the project.
19
+ * Make your feature addition or bug fix.
20
+ * Add tests for it. This is important so I don't break it in a
21
+ future version unintentionally.
22
+ * Commit, do not mess with rakefile, version, or history.
23
+ (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)
24
+ * Send me a pull request. Bonus points for topic branches.
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2010 thoughtbot. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "capybara-envjs-fixes"
8
+ gem.summary = %Q{Fixes on top of capybara-envjs}
9
+ gem.description = %Q{Fixes on top of capybara-envjs}
10
+ gem.email = "jmorrison@thoughtbot.com"
11
+ gem.homepage = "http://github.com/jasonm/capybara-envjs-fixes"
12
+ gem.authors = ["Jason Morrison"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency('capybara-envjs', '>= 0.1.6')
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "capybara-envjs-fixes #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.3
@@ -0,0 +1,61 @@
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{capybara-envjs-fixes}
8
+ s.version = "0.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jason Morrison"]
12
+ s.date = %q{2010-07-30}
13
+ s.description = %q{Fixes on top of capybara-envjs}
14
+ s.email = %q{jmorrison@thoughtbot.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "capybara-envjs-fixes.gemspec",
27
+ "lib/capybara_envjs_fixes/cucumber_fixes.rb",
28
+ "lib/capybara_envjs_fixes/cucumber_fixes/base64_upload.rb",
29
+ "lib/capybara_envjs_fixes/cucumber_fixes/capybara_extensions.rb",
30
+ "lib/capybara_envjs_fixes/cucumber_fixes/javascript.rb",
31
+ "spec/capybara-envjs-fixes_spec.rb",
32
+ "spec/spec.opts",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/jasonm/capybara-envjs-fixes}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Fixes on top of capybara-envjs}
40
+ s.test_files = [
41
+ "spec/capybara-envjs-fixes_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
51
+ s.add_runtime_dependency(%q<capybara-envjs>, [">= 0.1.6"])
52
+ else
53
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
54
+ s.add_dependency(%q<capybara-envjs>, [">= 0.1.6"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
58
+ s.add_dependency(%q<capybara-envjs>, [">= 0.1.6"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,3 @@
1
+ require 'capybara_envjs_fixes/cucumber_fixes/javascript'
2
+ require 'capybara_envjs_fixes/cucumber_fixes/capybara_extensions'
3
+ require 'capybara_envjs_fixes/cucumber_fixes/base64_upload'
@@ -0,0 +1,43 @@
1
+ # Capybara-envjs attempts to upload files encoded in Base64, which Rack doesn't decode
2
+ # TODO: extract this to fixes gem
3
+ class Base64UploadDecoder
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ Rack::Request.new(env).POST
10
+ if env['rack.request.form_hash']
11
+ decode_base64_uploads(env['rack.request.form_hash'])
12
+ end
13
+ @app.call(env)
14
+ end
15
+
16
+ private
17
+
18
+ def decode_base64_uploads(hash)
19
+ hash.each do |param, value|
20
+ if Hash === value
21
+ if value[:tempfile]
22
+ if value[:tempfile].read(512).include?('Content-Transfer-Encoding: base64')
23
+ value[:tempfile].rewind
24
+ lines = value[:tempfile].readlines
25
+ while (line = lines.shift) && !line.strip.empty?
26
+ end
27
+ new_temp = Tempfile.new("base64_decode")
28
+ new_temp.write Base64.decode64(lines.join)
29
+ value[:tempfile] = new_temp
30
+ else
31
+ value[:tempfile].rewind
32
+ end
33
+ else
34
+ decode_base64_uploads(value)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ Capybara.app = Base64UploadDecoder.new(Capybara.app)
42
+
43
+
@@ -0,0 +1,61 @@
1
+ class Capybara::Driver::Envjs::Node
2
+
3
+ def jquery_trigger(event)
4
+ driver.evaluate_script(<<-END_JS)
5
+ $('##{self['id']}').trigger('#{event}');
6
+ END_JS
7
+ end
8
+
9
+ def set_with_events(value)
10
+ case node.getAttribute("type")
11
+ when "checkbox", "radio"
12
+ set_radio(value)
13
+ else
14
+ set_text_input(value)
15
+ end
16
+ end
17
+ alias_method_chain :set, :events
18
+
19
+ def set_radio(value)
20
+ set_without_events(value)
21
+ jquery_trigger('change')
22
+ end
23
+
24
+ def set_text_input(value)
25
+ jquery_trigger('focus')
26
+ set_without_events(value)
27
+ jquery_trigger('keydown')
28
+ jquery_trigger('keyup')
29
+ jquery_trigger('change')
30
+ jquery_trigger('blur')
31
+ end
32
+
33
+ def select_with_events(options)
34
+ select_without_events(options)
35
+ jquery_trigger('change')
36
+ end
37
+ alias_method_chain :select, :events
38
+
39
+ # This is overridden because the default implementation only supports nodes
40
+ # hidden by setting the style attribute, which doesn't take into account the
41
+ # computed style
42
+ def visible?
43
+ all_unfiltered("./ancestor-or-self::*").none? do |capybara_node|
44
+ capybara_node.node.style['display'] == 'none'
45
+ end
46
+ end
47
+ end
48
+
49
+ class Capybara::Driver::Envjs
50
+ def env
51
+ env = {}
52
+ begin
53
+ @referrer = request.url if last_response.content_type.include?('text/html')
54
+ env["HTTP_REFERER"] = @referrer
55
+ rescue Rack::Test::Error
56
+ # no request yet
57
+ end
58
+ env
59
+ end
60
+ end
61
+
@@ -0,0 +1,69 @@
1
+ module CucumberJavascript
2
+ MOCK_DEBUG = %{
3
+ console = {
4
+ log: function (text) {
5
+ Ruby.Rails.logger().debug('*** Javascript: ' + text + ' ***');
6
+ }
7
+ };
8
+ }
9
+
10
+ MOCK_SET_TIMEOUT = %{
11
+ setTimeout = function() {
12
+ arguments[0].call();
13
+ };
14
+ }
15
+
16
+ MOCK_JQUERY_FADE = %{
17
+ (function() {
18
+ $.fn.fadeOut = function() {
19
+ if($.isFunction(arguments[0])) {
20
+ arguments[0].call();
21
+ } else if($.isFunction(arguments[1])) {
22
+ arguments[1].call();
23
+ }
24
+ return this;
25
+ };
26
+ $.fn.fadeIn = function() {
27
+ if($.isFunction(arguments[0])) {
28
+ arguments[0].call();
29
+ } else if($.isFunction(arguments[1])) {
30
+ arguments[1].call();
31
+ }
32
+ return this;
33
+ };
34
+ })();
35
+ }
36
+
37
+ MOCK_ENVJS = %{
38
+ /* fixes the .value property on textareas in env.js */
39
+ var extension = {
40
+ get value() { return this.innerText; },
41
+ set value(newValue) { this.innerText = newValue; }
42
+ };
43
+ var valueGetter = extension.__lookupGetter__('value');
44
+ HTMLTextAreaElement.prototype.__defineGetter__('value', valueGetter);
45
+ var valueSetter = extension.__lookupSetter__('value');
46
+ HTMLTextAreaElement.prototype.__defineSetter__('value', valueSetter);
47
+ }
48
+ MOCK_JAVASCRIPT = (MOCK_SET_TIMEOUT + MOCK_DEBUG + MOCK_ENVJS).freeze
49
+ MOCK_JQUERY = MOCK_JQUERY_FADE.freeze
50
+ end
51
+
52
+ Before('@javascript') do
53
+ @__custom_javascript = []
54
+ Capybara.current_session.driver.rack_mock_session.after_request do
55
+ new_body = Capybara.current_session.driver.response.body
56
+ new_body.gsub!("<head>",
57
+ %{"<head>
58
+ <script type="text/javascript">
59
+ #{CucumberJavascript::MOCK_JAVASCRIPT}
60
+ </script>})
61
+ new_body.sub!("</body>",
62
+ %{<script type="text/javascript">
63
+ #{CucumberJavascript::MOCK_JQUERY}
64
+ #{@__custom_javascript.join}
65
+ </body>})
66
+ new_body.gsub!(%r{<script src="http://[^"]+" type="text/javascript"></script>}, '')
67
+ Capybara.current_session.driver.response.instance_variable_set('@body', new_body)
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "CapybaraEnvjsFixes" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'capybara-envjs-fixes'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-envjs-fixes
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Jason Morrison
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-30 00:00:00 -04:00
19
+ default_executable:
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
+ - !ruby/object:Gem::Dependency
38
+ name: capybara-envjs
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 0
48
+ - 1
49
+ - 6
50
+ version: 0.1.6
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Fixes on top of capybara-envjs
54
+ email: jmorrison@thoughtbot.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - LICENSE
61
+ - README.rdoc
62
+ files:
63
+ - .document
64
+ - .gitignore
65
+ - LICENSE
66
+ - README.rdoc
67
+ - Rakefile
68
+ - VERSION
69
+ - capybara-envjs-fixes.gemspec
70
+ - lib/capybara_envjs_fixes/cucumber_fixes.rb
71
+ - lib/capybara_envjs_fixes/cucumber_fixes/base64_upload.rb
72
+ - lib/capybara_envjs_fixes/cucumber_fixes/capybara_extensions.rb
73
+ - lib/capybara_envjs_fixes/cucumber_fixes/javascript.rb
74
+ - spec/capybara-envjs-fixes_spec.rb
75
+ - spec/spec.opts
76
+ - spec/spec_helper.rb
77
+ has_rdoc: true
78
+ homepage: http://github.com/jasonm/capybara-envjs-fixes
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options:
83
+ - --charset=UTF-8
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.3.7
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Fixes on top of capybara-envjs
111
+ test_files:
112
+ - spec/capybara-envjs-fixes_spec.rb
113
+ - spec/spec_helper.rb