Skip to content

Commit 31bf155

Browse files
committed
Update rpsec setup to support other drivers
Also experiment with disabling animations in phantomjs. No matter what, I can't seem to get phantomjs or capybara-webkit to pass. Errors here: https://gist.github.com/justin808/5830adb7634e77db8c23
1 parent eebee78 commit 31bf155

11 files changed

+155
-56
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ vendor/ruby
3131

3232
# Rubymine/IntelliJ
3333
.idea
34+
35+
spec/examples.txt

Diff for: CHANGELOG.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
v1.1 - Sunday, March 22, 2015
2-
------------------------------
3-
1. Changed /webpack directory to /client
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
43

4+
See: [merged pull requests](https://github.com/shakacode/react-webpack-rails-tutorial/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Amerged).
5+
6+
## [2.1.0] - 2016-03-06
7+
### Updated
8+
- Changed properties for comments to have a top level name property comments.
59

6-
This is out of date.
10+
## 2.0.0 - 2016-03-05
11+
Baseline for Changelog
712

8-
See: [pull requests](https://github.com/shakacode/react-webpack-rails-tutorial/pulls?utf8=%E2%9C%93&q=is%3Apr)
13+
[2.1.0]: https://github.com/shakacode/react_on_rails/compare/2.1.0...2.0.0

Diff for: Gemfile

+6-4
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ end
9191

9292
group :test do
9393
gem "coveralls", require: false
94-
gem "rspec-rails"
95-
gem "rspec-retry"
9694
gem "capybara"
9795
gem "capybara-screenshot"
98-
gem "selenium-webdriver"
99-
gem "chromedriver-helper"
96+
gem "capybara-webkit"
97+
gem "chromedriver-helper", require: ["selenium_chrome"].include?(ENV["DRIVER"])
10098
gem "database_cleaner"
10199
gem "launchy"
100+
gem "poltergeist"# , require: ["poltergeist", "poltergeist_errors_ok"].include?(ENV["DRIVER"])
101+
gem "rspec-rails"
102+
gem "rspec-retry"
103+
gem "selenium-webdriver", require: !["poltergeist", "poltergeist_errors_ok", "webkit"].include?(ENV["DRIVER"])
102104
end

Diff for: Gemfile.lock

+14
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ GEM
7171
capybara-screenshot (1.0.11)
7272
capybara (>= 1.0, < 3)
7373
launchy
74+
capybara-webkit (1.8.0)
75+
capybara (>= 2.3.0, < 2.7.0)
76+
json
7477
childprocess (0.5.9)
7578
ffi (~> 1.0, >= 1.0.11)
7679
chromedriver-helper (1.0.0)
7780
archive-zip (~> 0.7.0)
7881
nokogiri (~> 1.6)
82+
cliver (0.3.2)
7983
coderay (1.1.1)
8084
coffee-rails (4.1.1)
8185
coffee-script (>= 2.2.0)
@@ -135,6 +139,11 @@ GEM
135139
parser (2.3.0.6)
136140
ast (~> 2.2)
137141
pg (0.18.4)
142+
poltergeist (1.9.0)
143+
capybara (~> 2.1)
144+
cliver (~> 0.3.1)
145+
multi_json (~> 1.0)
146+
websocket-driver (>= 0.2.0)
138147
powerpack (0.1.1)
139148
pry (0.10.3)
140149
coderay (~> 1.1.0)
@@ -298,6 +307,9 @@ GEM
298307
debug_inspector
299308
railties (>= 4.2)
300309
websocket (1.2.2)
310+
websocket-driver (0.6.3)
311+
websocket-extensions (>= 0.1.0)
312+
websocket-extensions (0.1.2)
301313
xpath (2.0.0)
302314
nokogiri (~> 1.3)
303315
yard (0.8.7.6)
@@ -312,6 +324,7 @@ DEPENDENCIES
312324
bundler-audit
313325
capybara
314326
capybara-screenshot
327+
capybara-webkit
315328
chromedriver-helper
316329
coffee-rails
317330
coveralls
@@ -321,6 +334,7 @@ DEPENDENCIES
321334
jbuilder
322335
launchy
323336
pg
337+
poltergeist
324338
pry
325339
pry-byebug
326340
pry-doc

Diff for: README.md

+16-20
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ By Justin Gordon and the Shaka Code Team, [www.shakacode.com](http://www.shakaco
1616
- Feel free to open discussions at [forum.shakacode.com](http://forum.shakacode.com). We love to help!
1717
- We now have a [gitter chat room for this topic](https://gitter.im/shakacode/react-webpack-rails-tutorial) but we prefer our Slack Channel ([email us](mailto:[email protected]) for an invite).
1818
- Check out the [react_on_rails gem](https://github.com/shakacode/react_on_rails) for easy webpack integration.
19-
- If you came to here from the blog article, this example project has evolved. See [pull requests](https://github.com/shakacode/react-webpack-rails-tutorial/pulls?utf8=%E2%9C%93&q=is%3Apr).
19+
- If you came to here from the blog article, this example project has evolved. See [merged pull requests](https://github.com/shakacode/react-webpack-rails-tutorial/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Amerged) and the [CHANGELOG.md](./CHANGELOG.md).
2020

21-
A Full tutorial article can be found at: [Fast Rich Client Rails Development With Webpack and the ES6 Transpiler](http://www.railsonmaui.com/blog/2014/10/03/integrating-webpack-and-the-es6-transpiler-into-an-existing-rails-project/). Note, this source code repository is way ahead of the tutorial. We plan to update the tutorial article as soon as we can catch our breath!
21+
An outdated full tutorial article behind of the motivation of this system can be found at: [Fast Rich Client Rails Development With Webpack and the ES6 Transpiler](http://www.railsonmaui.com/blog/2014/10/03/integrating-webpack-and-the-es6-transpiler-into-an-existing-rails-project/). Note, this source code repository is way ahead of the tutorial.
2222

2323
# NEWS
2424
We have not yet updated the `react_on_rails` gem generators for the following tasks. We're looking for help to migrate this, if you're interested in contributing to the project. *The tutorial* refers to this repo. The following changes have resulted in lots of differences for the webpack files and visual assets:
@@ -28,7 +28,6 @@ We have not yet updated the `react_on_rails` gem generators for the following ta
2828

2929
If you did generate a fresh app from React On Rails and want to move to CSS Modules, then see [PR 175: Babel 6 / CSS Modules / Rails hot reloading](https://github.com/shakacode/react-webpack-rails-tutorial/pull/175). Note, while there are probably fixes after this PR was accepted, this has the majority of the changes.
3030

31-
3231
# Example Application
3332
This is a simple example application that illustrates the use of ReactJs to implement a commenting system. Front-end code leverages both ReactJs and Rails asset pipeline while the backend is 100% Rails. It shows off a little bit of the interactivity of a ReactJs application, allowing the commmenter to choose the form layout. `react-bootstrap` is used for the React components. A pure Rails UI generated from scaffolding is shown for comparison.
3433

@@ -40,7 +39,7 @@ In no particular order:
4039

4140
- Example of using the [react_on_rails gem](https://github.com/shakacode/react_on_rails) for easy react/webpack integration with Rails.
4241
- Example of React with [CSS Modules](http://glenmaddern.com/articles/css-modules) inside of Rails using Webpack as described in [Smarter CSS builds with Webpack](http://bensmithett.com/smarter-css-builds-with-webpack/).
43-
- Example of enabling hot reloading of both JS and CSS from your Rails app in development mode. Change your code. Save. Browser updates without a refresh!
42+
- Example of enabling hot reloading of both JS and CSS (modules) from your Rails app in development mode. Change your code. Save. Browser updates without a refresh!
4443
- Example of Rails 4.2 with ReactJs/Redux/React-Router with Webpack and ES7.
4544
- Enabling development of a JS client independently from Rails using the [Webpack Dev Server](https://webpack.github.io/docs/webpack-dev-server.html). You can see this by starting the app and visiting http://localhost:4000
4645
- Enabling the use of npm modules and [Babel](https://babeljs.io/) with a Rails application using [Webpack](https://webpack.github.io/).
@@ -74,15 +73,23 @@ See package.json and Gemfile for versions
7473
1. `bundle install`
7574
1. `npm install`
7675
1. `rake db:setup`
77-
1. `foreman start -f Procfile.dev`
78-
1. Open a browser tab to http://localhost:3000 for the Rails app example.
79-
1. Open a browser tab to http://localhost:4000 for the Hot Module Replacement Example.
76+
1. `foreman start -f Procfile.hot`
77+
1. Open a browser tab to http://localhost:3000 for the Rails app example with HOT RELOADING
78+
2. Try Hot Reloading steps below!
79+
1. `foreman start -f Procfile.express`
80+
1. Open a browser tab to http://localhost:4000 for the Hot Module Replacement Example just using an express server (no Rails involved). This is good for fast prototyping of React components. However, this setup is not as useful now that we have hot reloading working for Rails!
81+
2. Try Hot Reloading steps below!
82+
1. `foreman start -f Procfile.static`
83+
1. Open a browser tab to http://localhost:3000 for the Rails app example.
84+
2. When you make changes, you have to refresh the browser page.
85+
86+
## Hot Reloading Example (applies to both `Procfile.hot` and `Procfile.express`.
8087
1. With the browser open to any JSX file, such as [client/app/bundles/comments/components/CommentBox/CommentBox.jsx](client/app/bundles/comments/components/CommentBox/CommentBox.jsx) and you can change the JSX code, hit save, and you will see the sceen update without refreshing the window. This applies to port 3000 and port 4000.
8188
1. Try changing a `.scss` file, such as a color in [client/app/bundles/comments/components/CommentBox/CommentList/Comment/Comment.scss](client/app/bundles/comments/components/CommentBox/CommentList/Comment/Comment.scss). You can see port 3000 or 4000 update automatically.
8289
1. Be sure to take a look at the different Procfiles in this directory, as described below.
8390

8491
# KEY COMMANDS
85-
1. Run all linters and tests: `rake ci`
92+
1. Run all linters and tests: `rake`
8693
1. See all npm commands: `npm run`
8794
1. Start all development processes: `foreman start -f Procfile.dev`
8895
1. Start all Rails only development processes: `foreman start -f Procfile.rails`
@@ -169,18 +176,7 @@ bundle exec foreman start -f <Procfile>
169176
In genereral, you want to avoid running more webpack watch processes than you need. The `Procfile.dev`, for example, runs both the express server (Webpack dev server) and the Rails hot assets reloading server.
170177

171178
## Contributors
172-
[The Shaka Code team!](http://www.shakacode.com/about/) and many others!
173-
174-
Notable contributions include (please submit PR if I miss any!):
175-
176-
* [Justin Gordon](https://github.com/justin808/): Started this, leads this
177-
* [Alex Fedoseev](https://github.com/alexfedoseev): Added integration of Rails hot loading and CSS modules, plus much more
178-
* [Martin Breining](https://github.com/mbreining): For adding flux at first
179-
* [Dylan Grafmyre](https://github.com/Dgrafmyre): For ci setup
180-
* [Rob Wise](https://github.com/robwise): Many doc improvements
181-
* [Josias Schneider](https://github.com/josiasd): Conversion to the new react_on_rails format
182-
183-
See the full list of [Contributors](https://github.com/shakacode/react-webpack-rails-tutorial/graphs/contributors)
179+
[The Shaka Code team!](http://www.shakacode.com/about/), led by [Justin Gordon](https://github.com/justin808/), along with with many others. See [contributors.md](docs/contributors.md)
184180

185181
# Open Code of Conduct
186182
This project adheres to the [Open Code of Conduct](http://todogroup.org/opencodeofconduct/#fetch/[email protected]). By participating, you are expected to uphold this code.

Diff for: config/database.yml

+21
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,24 @@ test:
2424
production:
2525
<<: *default
2626
database: db/production.sqlite3
27+
28+
# Uncomment below for a setup with just postgres and change your Gemfile to reflect this
29+
# default: &default
30+
# adapter: postgresql
31+
# username:
32+
# password:
33+
#
34+
# development:
35+
# <<: *default
36+
# database: tutorial_development
37+
#
38+
# # Warning: The database defined as "test" will be erased and
39+
# # re-generated from your development database when you run "rake".
40+
# # Do not set this db to the same as development or production.
41+
# test:
42+
# <<: *default
43+
# database: tutorial_test
44+
#
45+
#production:
46+
# <<: *default
47+
# database: tutorial_production

Diff for: config/initializers/react_on_rails.rb

+2
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
# Server rendering:
1818
config.server_renderer_pool_size = 1 # increase if you're on JRuby
1919
config.server_renderer_timeout = 20 # seconds
20+
21+
config.generated_assets_dirs = File.join(%w(app assets webpack))
2022
end

Diff for: docs/contributors.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Contributors
2+
3+
First, we love community contributions, as small as a one character doc fix! Please fork and submit a PR if you see something to improve of fix.
4+
5+
## Notable contributions include (please submit PR if I miss any!):
6+
7+
See the full list of [Contributors](https://github.com/shakacode/react-webpack-rails-tutorial/graphs/contributors)
8+
9+
* [Justin Gordon](https://github.com/justin808/): Started this, leads this
10+
* [Alex Fedoseev](https://github.com/alexfedoseev): Added integration of Rails hot loading and CSS modules, plus much more
11+
* [Martin Breining](https://github.com/mbreining): For adding flux at first
12+
* [Dylan Grafmyre](https://github.com/Dgrafmyre): For ci setup
13+
* [Rob Wise](https://github.com/robwise): Many doc improvements
14+
* [Josias Schneider](https://github.com/josiasd): Conversion to the new react_on_rails format

Diff for: spec/rails_helper.rb

+53-27
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
require "capybara/rspec"
99
require "capybara-screenshot/rspec"
1010

11-
# This will insert a <base> tag with the asset host into the pages created by
12-
# save_and_open_page, meaning that relative links will be loaded from the
13-
# development server if it is running.
14-
Capybara.asset_host = "http://localhost:3000"
15-
1611
# Add additional requires below this line. Rails is not loaded until this point!
1712

1813
# Requires supporting ruby files with custom matchers and macros, etc, in
@@ -42,50 +37,60 @@
4237
# Next line will ensure that assets are built if webpack -w is not running
4338
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
4439

45-
# config taken directly from RSpec example in the DatabaseCleaner README
46-
config.before(:suite) do
47-
DatabaseCleaner.strategy = :transaction
48-
DatabaseCleaner.clean_with :truncation
49-
end
40+
# Maybe selenium_firefox webdriver only works for Travis-CI builds.
41+
# 2016-03-06: Phantomjs, all options fails on MacOs
42+
# Same for webkit
43+
default_driver = :selenium_chrome
5044

51-
config.around(:each) do |example|
52-
DatabaseCleaner.cleaning do
53-
example.run
54-
end
55-
end
45+
supported_drivers = %i( poltergeist poltergeist_errors_ok
46+
poltergeist_no_animations webkit
47+
selenium_chrome selenium_firefox selenium)
48+
driver = ENV["DRIVER"].try(:to_sym) || default_driver
5649

57-
config.after(:each) do
58-
DatabaseCleaner.clean
50+
unless supported_drivers.include?(driver)
51+
raise "Unsupported driver: #{driver} (supported = #{supported_drivers})"
5952
end
6053

61-
# selenium_firefox webdriver only works for Travis-CI builds.
62-
driver = ENV["DRIVER"].try(:to_sym)
63-
if driver.nil? || driver == :selenium_chrome
54+
case driver
55+
when :poltergeist, :poltergeist_errors_ok, :poltergeist_no_animations
56+
require "capybara/poltergeist"
57+
opts = {
58+
extensions: ["#{Rails.root}/spec/support/phantomjs-disable-animations.js"]
59+
}
60+
61+
Capybara.register_driver :poltergeist_no_animations do |app|
62+
Capybara::Poltergeist::Driver.new(app, opts)
63+
end
64+
65+
Capybara.register_driver :poltergeist_errors_ok do |app|
66+
Capybara::Poltergeist::Driver.new(app, opts.merge(js_errors: false))
67+
end
68+
when :selenium_chrome
6469
Capybara.register_driver :selenium_chrome do |app|
6570
Capybara::Selenium::Driver.new(app, browser: :chrome)
6671
end
67-
Capybara.javascript_driver = :selenium_chrome
68-
6972
Capybara::Screenshot.register_driver(:selenium_chrome) do |js_driver, path|
7073
js_driver.browser.save_screenshot(path)
7174
end
72-
else
75+
when :selenium_firefox, :selenium
7376
Capybara.register_driver :selenium_firefox do |app|
7477
Capybara::Selenium::Driver.new(app, browser: :firefox)
7578
end
76-
Capybara.javascript_driver = :selenium_firefox
77-
7879
Capybara::Screenshot.register_driver(:selenium_firefox) do |js_driver, path|
7980
js_driver.browser.save_screenshot(path)
8081
end
82+
driver = :selenium_firefox
8183
end
8284

83-
Capybara.default_max_wait_time = 15
85+
Capybara.javascript_driver = driver
86+
87+
# Capybara.default_max_wait_time = 15
8488
puts "Capybara using driver: #{Capybara.javascript_driver}"
8589

8690
Capybara::Screenshot.prune_strategy = { keep: 10 }
91+
8792
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
88-
config.fixture_path = "#{::Rails.root}/spec/fixtures"
93+
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
8994

9095
# If you're not using ActiveRecord, or you'd prefer not to run each of your
9196
# examples within a transaction, remove the following line or assign false
@@ -106,4 +111,25 @@
106111
# The different available types are documented in the features, such as in
107112
# https://relishapp.com/rspec/rspec-rails/docs
108113
config.infer_spec_type_from_file_location!
114+
115+
# This will insert a <base> tag with the asset host into the pages created by
116+
# save_and_open_page, meaning that relative links will be loaded from the
117+
# development server if it is running.
118+
Capybara.asset_host = "http://localhost:3000"
119+
120+
# config taken directly from RSpec example in the DatabaseCleaner README
121+
config.before(:suite) do
122+
DatabaseCleaner.strategy = :transaction
123+
DatabaseCleaner.clean_with :truncation
124+
end
125+
126+
config.around(:each) do |example|
127+
DatabaseCleaner.cleaning do
128+
example.run
129+
end
130+
end
131+
132+
config.after(:each) do
133+
DatabaseCleaner.clean
134+
end
109135
end

Diff for: spec/spec_helper.rb

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
require "rspec/retry"
2121

2222
RSpec.configure do |config|
23+
config.example_status_persistence_file_path = "spec/examples.txt"
24+
config.run_all_when_everything_filtered = true
25+
2326
# rspec-expectations config goes here. You can use an alternate
2427
# assertion/expectation library such as wrong or the stdlib/minitest
2528
# assertions if you prefer.

Diff for: spec/support/phantomjs-disable-animations.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// https://gist.github.com/andyjbas/9962218
2+
// disable_animations.js
3+
var disableAnimationStyles = '-webkit-transition: none !important;' +
4+
'-moz-transition: none !important;' +
5+
'-ms-transition: none !important;' +
6+
'-o-transition: none !important;' +
7+
'transition: none !important;'
8+
9+
window.onload = function() {
10+
var animationStyles = document.createElement('style');
11+
animationStyles.type = 'text/css';
12+
animationStyles.innerHTML = '* {' + disableAnimationStyles + '}';
13+
document.head.appendChild(animationStyles);
14+
};

0 commit comments

Comments
 (0)