make_it_so 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dde582c517272c49eaf1cce483bc897a322fd122
4
- data.tar.gz: b01be3897cccc71c1a1d0ed97de3d02efe58b596
3
+ metadata.gz: 13620dc1e25ca2ec8c8ce9287aead4d7d9163761
4
+ data.tar.gz: ce95d6d68d4523f64088db6472f636f91c39a10b
5
5
  SHA512:
6
- metadata.gz: c77ad4e21bc38c48f1de992ea92b2fe4907b9503ab1d0a57c2f235dd2050fe909111163faf0a87b4019283a19a216af7c890d57aabf784806d34d55405904055
7
- data.tar.gz: '0681af42be621f03fd0bc6b4b371257c7ba504e54f607280fa52fd06daeedc0e147e9c025bfd6aefa93a46a08136c58eb2af617eb1b2cf0d6c4a5db4bcfe33ca'
6
+ metadata.gz: 23c4bcd4f977f73fc2b0e1504e228fa3c612403017950575bbd13669cb96138a0137e27c7fbadc20e881914813babc66f85d4f56fc954e621a70877a3fed91be
7
+ data.tar.gz: ef357898432dbf513c5f569af5ad6b5cbfd244accc53b77555d8bc80747c1c70684a96d35968226508363e7ab9b886b689e05e782bdadede8bb74128131d8b3a
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ tags
@@ -24,7 +24,7 @@ module MakeItSo
24
24
  class_option :foundation,
25
25
  type: :boolean,
26
26
  default: true,
27
- desc: 'generate foundation support'
27
+ desc: 'Generate foundation support'
28
28
 
29
29
  # turbolinks is the devil
30
30
  class_option :skip_turbolinks,
@@ -32,6 +32,26 @@ module MakeItSo
32
32
  default: true,
33
33
  desc: 'Skip turbolinks gem'
34
34
 
35
+ class_option :skip_coffee,
36
+ type: :boolean,
37
+ default: true,
38
+ desc: 'Skip coffee gem'
39
+
40
+ class_option :skip_spring,
41
+ type: :boolean,
42
+ default: true,
43
+ desc: 'Skip spring gem'
44
+
45
+ class_option :react,
46
+ type: :boolean,
47
+ default: true,
48
+ desc: 'Generate React setup'
49
+
50
+ class_option :karma,
51
+ type: :boolean,
52
+ default: true,
53
+ desc: 'Generate karma testing setup'
54
+
35
55
  def initialize(*args)
36
56
  super
37
57
  if @options[:rspec]
@@ -58,7 +78,6 @@ module MakeItSo
58
78
  build 'factory_bot_rspec'
59
79
  build 'valid_attribute_rspec'
60
80
  build 'shoulda_rspec'
61
- build 'teaspoon_jasmine'
62
81
  end
63
82
 
64
83
  if options[:devise]
@@ -68,6 +87,14 @@ module MakeItSo
68
87
  if options[:foundation]
69
88
  build 'foundation_dependency'
70
89
  end
90
+
91
+ if options[:react]
92
+ build 'react'
93
+ end
94
+
95
+ if options[:karma]
96
+ build 'karma'
97
+ end
71
98
  end
72
99
 
73
100
  protected
@@ -1,4 +1,5 @@
1
1
  require 'rails/generators/rails/app/app_generator'
2
+ require 'json'
2
3
 
3
4
  module MakeItSo
4
5
  module Rails
@@ -36,6 +37,49 @@ module MakeItSo
36
37
  gsub_file 'Gemfile', both_lines, "\n"
37
38
  end
38
39
 
40
+ def react
41
+ self.gem 'webpacker', '~> 3.0.2'
42
+
43
+ after_bundle do
44
+ rake 'webpacker:install'
45
+ rake 'webpacker:install:react'
46
+
47
+ unparsed_json = snippet('react_dependencies.json')
48
+ parsed_json = JSON.parse(unparsed_json)
49
+
50
+ modify_json(package_json_file) do |json|
51
+ ["dependencies", "devDependencies"].each do |key|
52
+ json[key] ||= {}
53
+ json[key].merge!(parsed_json[key])
54
+ end
55
+ end
56
+
57
+ rake 'yarn:install'
58
+ end
59
+ end
60
+
61
+ def karma
62
+ after_bundle do
63
+ unparsed_json = snippet('js_testing_deps.json')
64
+ parsed_json = JSON.parse(unparsed_json)
65
+
66
+ modify_json(package_json_file) do |json|
67
+ json["devDependencies"] ||= {}
68
+ json["devDependencies"].merge!(parsed_json["devDependencies"])
69
+ json["scripts"] ||= {}
70
+ json["scripts"]["test"] = "node_modules/.bin/karma start karma.conf.js"
71
+ end
72
+
73
+ template 'karma.conf.js'
74
+ inside 'spec/javascript' do
75
+ template 'exampleTest.js'
76
+ template 'testHelper.js'
77
+ end
78
+
79
+ rake 'yarn:install'
80
+ end
81
+ end
82
+
39
83
  def rspec_dependency
40
84
  self.gem 'rspec-rails', group: [:development, :test]
41
85
  self.gem 'capybara', group: [:development, :test]
@@ -105,13 +149,6 @@ module MakeItSo
105
149
  end
106
150
  end
107
151
 
108
- def teaspoon_jasmine
109
- self.gem 'teaspoon-jasmine'
110
- after_bundle do
111
- generate 'teaspoon:install'
112
- end
113
- end
114
-
115
152
  def devise_dependency
116
153
  self.gem 'devise'
117
154
 
@@ -152,6 +189,29 @@ module MakeItSo
152
189
  end
153
190
 
154
191
  protected
192
+ PACKAGE_PATH = 'package.json'
193
+ WEBCONFIG_PATH = 'webpack.config.js'
194
+
195
+ protected
196
+ def parsed_package_json
197
+ @package_json ||= parse_json_file(package_json_file)
198
+ end
199
+
200
+ def package_json_file
201
+ File.join(destination_root, PACKAGE_PATH)
202
+ end
203
+
204
+ def modify_json(file, &block)
205
+ json = parse_json_file(file)
206
+ block.call(json)
207
+ File.write(file, JSON.pretty_generate(json))
208
+ end
209
+
210
+ def parse_json_file(file)
211
+ contents = File.read(file)
212
+ JSON.parse(contents)
213
+ end
214
+
155
215
  def rails_helper_insertion_hook
156
216
  "require 'rspec/rails'\n"
157
217
  end
@@ -1,3 +1,3 @@
1
1
  module MakeItSo
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
data/make_it_so.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "thor"
22
22
  spec.add_dependency "railties", "~> 5.1"
23
+ spec.add_dependency "json"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.7"
25
26
  spec.add_development_dependency "appraisal"
@@ -0,0 +1,18 @@
1
+ {
2
+ "devDependencies": {
3
+ "enzyme": "~2.9.1",
4
+ "jasmine-ajax": "3.2.0",
5
+ "jasmine-core": "~2.4.1",
6
+ "jasmine-enzyme": "~3.4.0",
7
+ "karma": "~0.13.22",
8
+ "karma-coverage": "0.5.5",
9
+ "karma-jasmine": "~0.3.8",
10
+ "karma-phantomjs-launcher": "~1.0.4",
11
+ "karma-sourcemap-loader": "0.3.7",
12
+ "karma-spec-reporter": "0.0.26",
13
+ "karma-webpack": "2.0.1",
14
+ "phantomjs-prebuilt": "~2.1.14",
15
+ "react-addons-test-utils": "~15.6.2"
16
+ }
17
+ }
18
+
@@ -0,0 +1,12 @@
1
+ {
2
+ "dependencies": {
3
+ "@rails/webpacker": "~3.0.2",
4
+ "babel-preset-react": "~6.24.1",
5
+ "prop-types": "~15.6.0",
6
+ "react": "~15.4.2",
7
+ "react-dom": "~15.4.2"
8
+ },
9
+ "devDependencies": {
10
+ "webpack-dev-server": "~2.4.2"
11
+ }
12
+ }
@@ -12,6 +12,7 @@ feature 'user generates rails app' do
12
12
  let(:css_manifest_path) { join_paths(app_path, 'app/assets/stylesheets/application.css') }
13
13
 
14
14
  let(:gemfile_path) { join_paths(app_path, 'Gemfile')}
15
+ let(:package_json_path) { join_paths(app_path, 'package.json')}
15
16
  let(:rails_spec_helper) { join_paths(app_path, 'spec/rails_helper.rb')}
16
17
 
17
18
  before(:all) do
@@ -130,16 +131,6 @@ feature 'user generates rails app' do
130
131
  to include("require 'shoulda-matchers'")
131
132
  end
132
133
  end
133
-
134
- context 'teaspoon' do
135
- it 'includes teaspoon-jasmine in the Gemfile' do
136
- expect(File.read(gemfile_path)).to include('teaspoon-jasmine')
137
- end
138
-
139
- it 'generates a spec/javascripts directory' do
140
- expect(FileTest.exists?(join_paths(app_path, 'spec/javascripts'))).to eq(true)
141
- end
142
- end
143
134
  end
144
135
 
145
136
  context 'devise' do
@@ -187,4 +178,53 @@ feature 'user generates rails app' do
187
178
  expect(File.read(File.join(app_path, 'app/views/layouts/application.html.erb'))).to include('modernizr')
188
179
  end
189
180
  end
181
+
182
+ context 'react' do
183
+ it 'generates a packs file' do
184
+ expect(FileTest.exists?(join_paths(app_path, 'app/javascript/packs/application.js'))).to eq(true)
185
+ end
186
+
187
+ it 'includes react in package.json' do
188
+ in_package_json?(File.join(app_path, 'package.json')) do |json|
189
+ expect(json["dependencies"]["react"]).to_not be_nil
190
+ end
191
+ end
192
+
193
+ it 'includes react-dom in package.json' do
194
+ in_package_json?(File.join(app_path, 'package.json')) do |json|
195
+ expect(json["dependencies"]["react-dom"]).to_not be_nil
196
+ end
197
+ end
198
+ end
199
+
200
+ context 'karma' do
201
+ it 'creates a karma.config' do
202
+ karma_config = File.join(app_path, 'karma.conf.js')
203
+ expect(FileTest.exists?(karma_config)).to eq(true)
204
+ end
205
+
206
+ it 'creates a testHelper.js' do
207
+ test_helper = File.join(app_path, 'spec/javascript/testHelper.js')
208
+ expect(FileTest.exists?(test_helper)).to eq(true)
209
+ end
210
+
211
+ it 'includes karma in package.json' do
212
+ in_package_json?(File.join(app_path, 'package.json')) do |json|
213
+ expect(json["devDependencies"]["karma"]).to_not be_nil
214
+ end
215
+ end
216
+
217
+ it 'includes jasmine in package.json' do
218
+ in_package_json?(File.join(app_path, 'package.json')) do |json|
219
+ expect(json["devDependencies"]["jasmine-core"]).to_not be_nil
220
+ end
221
+ end
222
+
223
+ it 'includes react-addons-test-utils' do
224
+ in_package_json?(File.join(app_path, 'package.json')) do |json|
225
+ expect(json["devDependencies"]["react-addons-test-utils"]).to_not be_nil
226
+ end
227
+
228
+ end
229
+ end
190
230
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'bundler/setup'
2
2
  require 'rspec'
3
3
  require 'capybara/rspec'
4
+ require 'json'
4
5
 
5
6
  Bundler.require(:default, :test)
6
7
 
@@ -44,6 +44,12 @@ module MakeItSoSpecHelpers
44
44
  File.read(join_paths(app_path, 'Gemfile')).
45
45
  match(/gem.*#{Regexp.escape(gem_name)}/).present?
46
46
  end
47
+
48
+ def in_package_json?(path, &block)
49
+ contents = File.read(path)
50
+ json = JSON.parse(contents)
51
+ yield(json)
52
+ end
47
53
  end
48
54
 
49
55
  RSpec.configure do |config|
@@ -0,0 +1,94 @@
1
+ var path = require('path');
2
+
3
+ module.exports = function(config) {
4
+ config.set({
5
+ basePath: "",
6
+ // use the PhantomJS browser
7
+ browsers: ['PhantomJS'],
8
+
9
+ // use the Jasmine testing framework
10
+ frameworks: ['jasmine'],
11
+
12
+ // files that Karma will server to the browser
13
+ files: [
14
+ // use Babel polyfill to emulate a full ES6 environment in PhantomJS
15
+ 'node_modules/babel-polyfill/dist/polyfill.js',
16
+ // entry file for Webpack
17
+ 'spec/javascript/testHelper.js'
18
+ ],
19
+
20
+ // before serving test/testHelper.js to the browser
21
+ preprocessors: {
22
+ 'spec/javascript/testHelper.js': [
23
+ // use karma-webpack to preprocess the file via webpack
24
+ 'webpack',
25
+ // use karma-sourcemap-loader to utilize sourcemaps generated by webpack
26
+ 'sourcemap'
27
+ ]
28
+ },
29
+
30
+ // webpack configuration used by karma-webpack
31
+ webpack: {
32
+ // generate sourcemaps
33
+ devtool: 'eval-source-map',
34
+ module: {
35
+ loaders: [
36
+ // use babel-loader to transpile the test and src folders
37
+ {
38
+ test: /\.jsx?$/,
39
+ exclude: /node_modules/,
40
+ loader: 'babel-loader'
41
+ },
42
+ {
43
+ test: /\.json$/,
44
+ include: [
45
+ /node_modules/,
46
+ path.resolve(__dirname, '..')
47
+ ],
48
+ loader: 'json-loader'
49
+ }
50
+ ]
51
+ },
52
+ resolve: {
53
+ modules: ['app/javascript', 'node_modules']
54
+ }
55
+ },
56
+
57
+ webpackMiddleware: {
58
+ // do not output webpack build information to the browser's console
59
+ noInfo: true
60
+ },
61
+
62
+ // test reporters that Karma should use
63
+ reporters: [
64
+ // use karma-spec-reporter to report results to the browser's console
65
+ 'spec',
66
+ // use karma-coverage to report test coverage
67
+ 'coverage'
68
+ ],
69
+
70
+ // karma-spec-reporter configuration
71
+ specReporter: {
72
+ // remove meaningless stack trace when tests do not pass
73
+ maxLogLines: 1,
74
+ // do not print information about tests that are passing
75
+ suppressPassed: true
76
+ },
77
+
78
+ // karma-coverage configuration
79
+ coverageReporter: {
80
+ // output coverage results to the coverage folder in the project's root
81
+ dir: 'coverage',
82
+ subdir: '.',
83
+ // output coverage results as html
84
+ type: 'html'
85
+ },
86
+ externals: {
87
+ cheerio: 'window',
88
+ 'react/addons': true,
89
+ 'react/lib/ExecutionEnvironment': true,
90
+ 'react/lib/ReactContext': true,
91
+ 'react/addons': true
92
+ }
93
+ })
94
+ }
@@ -0,0 +1,5 @@
1
+ describe('example test', () => {
2
+ it('should pass', () => {
3
+ expect(true).toBe(true);
4
+ });
5
+ });
@@ -0,0 +1,29 @@
1
+ import { shallow, mount } from 'enzyme';
2
+ import jasmineEnzyme from 'jasmine-enzyme';
3
+ import React from 'react';
4
+ import 'jasmine-ajax';
5
+
6
+ Object.assign(global, {
7
+ jasmineEnzyme,
8
+ mount,
9
+ React,
10
+ shallow,
11
+ });
12
+
13
+ beforeEach(() => {
14
+ jasmineEnzyme();
15
+ });
16
+
17
+ // function to require all modules for a given context
18
+ let requireAll = requireContext => {
19
+ requireContext.keys().forEach(requireContext);
20
+ };
21
+
22
+ // require all js files except testHelper.js in the test folder
23
+ requireAll(require.context('./', true, /^((?!testHelper).)*\.jsx?$/));
24
+
25
+ // require all js files except main.js in the src folder
26
+ requireAll(require.context('../../app/javascript', true, /^((?!application).)*\.jsx?$/));
27
+
28
+ // output to the browser's console when the tests run
29
+ console.info(`TESTS RAN AT ${new Date().toLocaleTimeString()}`);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: make_it_so
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pickett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-10 00:00:00.000000000 Z
11
+ date: 2017-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +154,8 @@ files:
140
154
  - lib/make_it_so/version.rb
141
155
  - make_it_so.gemspec
142
156
  - snippets/rails/application_generator.rb
157
+ - snippets/rails/js_testing_deps.json
158
+ - snippets/rails/react_dependencies.json
143
159
  - snippets/rails/user_factory.rb
144
160
  - spec/features/user_generates_gosu_spec.rb
145
161
  - spec/features/user_generates_rails_spec.rb
@@ -160,9 +176,12 @@ files:
160
176
  - templates/rails/app/controllers/homes_controller.rb
161
177
  - templates/rails/app/views/homes/index.html.erb
162
178
  - templates/rails/app/views/layouts/application.html.erb.tt
179
+ - templates/rails/karma.conf.js
163
180
  - templates/rails/spec/features/user_signs_in_spec.rb
164
181
  - templates/rails/spec/features/user_signs_out_spec.rb
165
182
  - templates/rails/spec/features/user_signs_up_spec.rb
183
+ - templates/rails/spec/javascript/exampleTest.js
184
+ - templates/rails/spec/javascript/testHelper.js
166
185
  - templates/rails/spec/support/factory_bot.rb
167
186
  - templates/rails/spec/support/valid_attribute.rb
168
187
  - templates/sinatra/.gitignore