polychrest 0.0.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/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in polychrest.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| ["spec/lib/#{m[1]}_spec.rb", "spec/integration/#{m[1]}_spec.rb"] }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Polychrest
2
+
3
+ Rack middleware to trap javascript errors and inject them in the DOM so capybara drivers without javascript error reporting can find them.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'polychrest'
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install polychrest
18
+
19
+ ## Usage
20
+
21
+ Polychrest will only inject script if the environment variable `TRACK_JS_ERRORS` is set:
22
+
23
+ $ export TRACK_JS_ERRORS; cucumber
24
+
25
+ or set it in a hook:
26
+
27
+ Around('@javascript') do |scenario, block|
28
+ ENV['TRACK_JS_ERRORS'] = 'true'
29
+ block.call
30
+ ENV.delete('TRACK_JS_ERRORS')
31
+ end
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize!
7
+ run Combustion::Application
data/lib/polychrest.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "polychrest/version"
2
+ require "polychrest/cure"
3
+
4
+ module Polychrest
5
+ end
6
+
7
+ require 'polychrest/railtie' if defined?(Rails)
@@ -0,0 +1,33 @@
1
+ require 'nokogiri'
2
+ require 'polychrest/ingredients'
3
+
4
+ module Polychrest
5
+ class Cure
6
+
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ status, headers, response = @app.call(env)
13
+
14
+ if headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/ && ENV.has_key?('TRACK_JS_ERRORS')
15
+ body = ""
16
+ response.each { |part| body << part }
17
+ doc = Nokogiri::HTML(body)
18
+
19
+ head = doc.at_css("head")
20
+ script = Nokogiri::XML::Node.new('script', doc)
21
+ script.content = Polychrest::Ingredients.active
22
+ head.add_child(script)
23
+
24
+ body = doc.to_html
25
+
26
+ headers["Content-Length"] = body.length.to_s
27
+ response = [body]
28
+ end
29
+
30
+ [status, headers, response]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ module Polychrest
2
+ class Ingredients
3
+ def self.active
4
+ return<<-EOF
5
+ //<![CDATA[
6
+ window.onerror=function(msg){
7
+ var errorDiv = document.createElement('div');
8
+ errorDiv.className = 'js_errors';
9
+ errorDiv.setAttribute('style','height: 1px; width: 1px; overflow: hidden; position: absolute; left: -1000px;');
10
+ errorDiv.innerHTML = msg;
11
+ document.body.appendChild(errorDiv);
12
+ return true;
13
+ }
14
+ //]]>
15
+ EOF
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails'
2
+
3
+ class PolychrestRailtie < Rails::Railtie
4
+ initializer "polychrest_railtie.configure_rails_initialization" do |app|
5
+ app.middleware.use Polychrest::Cure
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Polychrest
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "polychrest/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "polychrest"
7
+ s.version = Polychrest::VERSION
8
+ s.authors = ["TA Tyree"]
9
+ s.email = ["tatyree@gmail.com"]
10
+ s.homepage = "https://github.com/lonelyplanet/polychrest"
11
+ s.summary = %q{Cure your javascript ills with illumination, elucidation and extra Sauce.}
12
+ s.description = %q{A middleware engine to trap javascript errors and write them to a hidden, but inspectible place in the DOM. }
13
+
14
+ s.rubyforge_project = "polychrest"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency 'rspec', "~> 2.10"
22
+ s.add_development_dependency 'rails', "~> 3.2"
23
+ s.add_development_dependency 'capybara'
24
+ s.add_development_dependency 'guard'
25
+ s.add_development_dependency 'guard-rspec'
26
+ s.add_development_dependency 'combustion'
27
+ s.add_development_dependency 'sqlite3'
28
+
29
+ s.add_dependency 'nokogiri'
30
+ end
data/rvmrc.example ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@polychrest
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe "It adds the javascript whats needful" do
4
+
5
+ it "should not add any javascript if the environment variable is missing" do
6
+ ENV['TRACK_JS_ERRORS'] = nil
7
+ visit '/'
8
+ page.should_not have_css('script')
9
+ end
10
+
11
+ it "should add a javascript tag to the head if the enviroment variable is set" do
12
+ ENV['TRACK_JS_ERRORS'] = 'true'
13
+ Polychrest::Ingredients.stub(:active).and_return("alert('BLAST AND DAMN!');")
14
+ visit '/'
15
+ page.should have_css('head script', :text => "alert('BLAST AND DAMN!');")
16
+ ENV['TRACK_JS_ERRORS'] = nil
17
+ end
18
+
19
+ context "the real javascript" do
20
+ before(:each) do
21
+ ENV['TRACK_JS_ERRORS'] = 'true'
22
+ end
23
+
24
+ after(:each) do
25
+ ENV['TRACK_JS_ERRORS'] = nil
26
+ end
27
+
28
+ it "should not write errors in the dom if there aren't any errors.", :js => true do
29
+ ShipsController.should_receive(:javascript_to_show).and_return("var textNode = document.createTextNode('Copper Bottomed');")
30
+ visit '/ships/1'
31
+ page.should_not have_css('.js_errors')
32
+ end
33
+
34
+ it "should write errors in the dom if there are errors.", :js => true do
35
+ ShipsController.should_receive(:javascript_to_show).and_return("var textNode = createTextNode('Copper Bottomed');")
36
+ visit '/ships/1'
37
+ page.should have_css('.js_errors', text: /createTextNode/i)
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,14 @@
1
+ class ShipsController < ActionController::Base
2
+ layout 'application'
3
+ def index
4
+
5
+ end
6
+
7
+ def show
8
+ @ship = ShipsController.javascript_to_show
9
+ end
10
+
11
+ def self.javascript_to_show
12
+ "var textNode = document.createTextNode('Copper Bottomed');"
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Polychrest
6
+ </title>
7
+ </head>
8
+ <body>
9
+ <%= yield %>
10
+ </body>
11
+ </html>
@@ -0,0 +1,5 @@
1
+ <h1>
2
+ She was known as the Carpenter’s Mistake, and no one in the service had ever imagined she would be launched.
3
+ - Post Captain
4
+ microsoft
5
+ </h1>
@@ -0,0 +1,4 @@
1
+ <h1><%= @ship %></h1>
2
+ <script>
3
+ <%= @ship %>
4
+ </script>
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/combustion_test.sqlite
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ resources :ships
3
+
4
+ root :to => 'ships#index'
5
+ end
@@ -0,0 +1,3 @@
1
+ ActiveRecord::Schema.define do
2
+ #
3
+ end
@@ -0,0 +1 @@
1
+ *.log
File without changes
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'rails'
4
+
5
+ Bundler.require :default, :development
6
+
7
+ require 'capybara/rspec'
8
+
9
+ Combustion.initialize! :action_controller, :action_view
10
+
11
+ require 'rspec'
12
+ require 'capybara/rails'
13
+
14
+ RSpec.configure do |config|
15
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polychrest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TA Tyree
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2160297620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2160297620
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &2160265780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2160265780
36
+ - !ruby/object:Gem::Dependency
37
+ name: capybara
38
+ requirement: &2160265020 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2160265020
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard
49
+ requirement: &2160263940 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2160263940
58
+ - !ruby/object:Gem::Dependency
59
+ name: guard-rspec
60
+ requirement: &2160263480 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2160263480
69
+ - !ruby/object:Gem::Dependency
70
+ name: combustion
71
+ requirement: &2160263000 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2160263000
80
+ - !ruby/object:Gem::Dependency
81
+ name: sqlite3
82
+ requirement: &2160262500 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2160262500
91
+ - !ruby/object:Gem::Dependency
92
+ name: nokogiri
93
+ requirement: &2160261900 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: *2160261900
102
+ description: ! 'A middleware engine to trap javascript errors and write them to a
103
+ hidden, but inspectible place in the DOM. '
104
+ email:
105
+ - tatyree@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - .gitignore
111
+ - Gemfile
112
+ - Guardfile
113
+ - README.md
114
+ - Rakefile
115
+ - config.ru
116
+ - lib/polychrest.rb
117
+ - lib/polychrest/cure.rb
118
+ - lib/polychrest/ingredients.rb
119
+ - lib/polychrest/railtie.rb
120
+ - lib/polychrest/version.rb
121
+ - polychrest.gemspec
122
+ - rvmrc.example
123
+ - spec/integration/polychrest_spec.rb
124
+ - spec/internal/app/controllers/ships_controller.rb
125
+ - spec/internal/app/views/layouts/application.html.erb
126
+ - spec/internal/app/views/ships/index.html.erb
127
+ - spec/internal/app/views/ships/show.html.erb
128
+ - spec/internal/config/database.yml
129
+ - spec/internal/config/routes.rb
130
+ - spec/internal/db/schema.rb
131
+ - spec/internal/log/.gitignore
132
+ - spec/internal/public/favicon.ico
133
+ - spec/spec_helper.rb
134
+ homepage: https://github.com/lonelyplanet/polychrest
135
+ licenses: []
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project: polychrest
154
+ rubygems_version: 1.8.10
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: Cure your javascript ills with illumination, elucidation and extra Sauce.
158
+ test_files:
159
+ - spec/integration/polychrest_spec.rb
160
+ - spec/internal/app/controllers/ships_controller.rb
161
+ - spec/internal/app/views/layouts/application.html.erb
162
+ - spec/internal/app/views/ships/index.html.erb
163
+ - spec/internal/app/views/ships/show.html.erb
164
+ - spec/internal/config/database.yml
165
+ - spec/internal/config/routes.rb
166
+ - spec/internal/db/schema.rb
167
+ - spec/internal/log/.gitignore
168
+ - spec/internal/public/favicon.ico
169
+ - spec/spec_helper.rb