diff --git a/Appraisals b/Appraisals index 68e117469..ea0409e91 100644 --- a/Appraisals +++ b/Appraisals @@ -43,7 +43,6 @@ appraise "rails-4.2-sprockets_4" do gem 'rails', '~> 4.2.1' gem "sprockets", "~> 4.0.x" gem "turbolinks", "~> 2.5.0" - gem "webpacker", github: "rails/webpacker" # This ExecJS backend provides stateful context # which the default nodejs backend does not gem "mini_racer" @@ -51,22 +50,18 @@ end appraise "rails-5_no_sprockets_webpacker" do gem 'rails', '~> 5.0.0' - gem "webpacker", github: "rails/webpacker" + gem "webpacker", '< 3.0' # This ExecJS backend provides stateful context # which the default nodejs backend does not gem "therubyracer" end appraise "rails-5-no_sprockets" do - # Appraisal adds `turbolinks` to this gemfile because it is - # present in `./Gemfile`. - # But it causes this gemfile to break, so it must be removed - # from `./gemfiles/rails_5_no_sprockets.gemfile` manually. gem 'rails', '~> 5.0.0' end appraise "rails-5.1-sprockets_4" do - gem "rails", "5.1.0.rc1" + gem "rails", "~> 5.1.0" gem "sprockets", "~> 4.0.x" gem "turbolinks", "~> 5.0.0" end diff --git a/Gemfile b/Gemfile index f79b8769c..d65e2a669 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ source 'http://rubygems.org' gemspec -# This is an optional dev-dependency, required whenever sprockets is required -gem "turbolinks" diff --git a/gemfiles/rails_3.2.gemfile b/gemfiles/rails_3.2.gemfile index 72db331b6..f93296133 100644 --- a/gemfiles/rails_3.2.gemfile +++ b/gemfiles/rails_3.2.gemfile @@ -2,8 +2,8 @@ source "http://rubygems.org" -gem "turbolinks", "~> 2.0" gem "rails", "~> 3.2.21" gem "rack-cache", "~> 1.6.1" +gem "turbolinks", "~> 2.0" gemspec :path => "../" diff --git a/gemfiles/rails_4.0.5.gemfile b/gemfiles/rails_4.0.5.gemfile index e9e0ccfcf..eeb73d957 100644 --- a/gemfiles/rails_4.0.5.gemfile +++ b/gemfiles/rails_4.0.5.gemfile @@ -2,7 +2,7 @@ source "http://rubygems.org" -gem "turbolinks" gem "rails", "4.0.5" +gem "turbolinks" gemspec :path => "../" diff --git a/gemfiles/rails_4.0_with_therubyracer.gemfile b/gemfiles/rails_4.0_with_therubyracer.gemfile index de6505b1c..4c854cc34 100644 --- a/gemfiles/rails_4.0_with_therubyracer.gemfile +++ b/gemfiles/rails_4.0_with_therubyracer.gemfile @@ -2,8 +2,8 @@ source "http://rubygems.org" -gem "turbolinks" gem "rails", "~> 4.0.13" gem "therubyracer", "0.12.0", :platform => :mri +gem "turbolinks" gemspec :path => "../" diff --git a/gemfiles/rails_4.1.gemfile b/gemfiles/rails_4.1.gemfile index 976f20e9d..80206ebca 100644 --- a/gemfiles/rails_4.1.gemfile +++ b/gemfiles/rails_4.1.gemfile @@ -2,7 +2,7 @@ source "http://rubygems.org" -gem "turbolinks", "~> 2.3.0" gem "rails", "~> 4.1.10" +gem "turbolinks", "~> 2.3.0" gemspec :path => "../" diff --git a/gemfiles/rails_4.2_sprockets_2.gemfile b/gemfiles/rails_4.2_sprockets_2.gemfile index 02aeb7502..d31127374 100644 --- a/gemfiles/rails_4.2_sprockets_2.gemfile +++ b/gemfiles/rails_4.2_sprockets_2.gemfile @@ -2,8 +2,8 @@ source "http://rubygems.org" -gem "turbolinks" gem "rails", "~> 4.2.1" gem "sprockets", "~> 2.12" +gem "turbolinks" gemspec :path => "../" diff --git a/gemfiles/rails_4.2_sprockets_3.gemfile b/gemfiles/rails_4.2_sprockets_3.gemfile index 6ac755f7d..7bb53f889 100644 --- a/gemfiles/rails_4.2_sprockets_3.gemfile +++ b/gemfiles/rails_4.2_sprockets_3.gemfile @@ -2,8 +2,8 @@ source "http://rubygems.org" -gem "turbolinks", "~> 2.5.0" gem "rails", "~> 4.2.1" gem "sprockets", "~> 3.5" +gem "turbolinks", "~> 2.5.0" gemspec :path => "../" diff --git a/gemfiles/rails_4.2_sprockets_4.gemfile b/gemfiles/rails_4.2_sprockets_4.gemfile index 2f661f0c0..e5b8484a7 100644 --- a/gemfiles/rails_4.2_sprockets_4.gemfile +++ b/gemfiles/rails_4.2_sprockets_4.gemfile @@ -2,10 +2,9 @@ source "http://rubygems.org" -gem "turbolinks", "~> 2.5.0" gem "rails", "~> 4.2.1" gem "sprockets", "~> 4.0.x" -gem "webpacker", :github => "rails/webpacker" +gem "turbolinks", "~> 2.5.0" gem "mini_racer" gemspec :path => "../" diff --git a/gemfiles/rails_5.1_sprockets_4.gemfile b/gemfiles/rails_5.1_sprockets_4.gemfile index 30ea5c1c3..7588f0512 100644 --- a/gemfiles/rails_5.1_sprockets_4.gemfile +++ b/gemfiles/rails_5.1_sprockets_4.gemfile @@ -2,8 +2,8 @@ source "http://rubygems.org" -gem "turbolinks", "~> 5.0.0" -gem "rails", "5.1.0.rc1" +gem "rails", "~> 5.1.0" gem "sprockets", "~> 4.0.x" +gem "turbolinks", "~> 5.0.0" gemspec :path => "../" diff --git a/gemfiles/rails_5_no_sprockets.gemfile b/gemfiles/rails_5_no_sprockets.gemfile index 2d5f543d0..c2b8165cf 100644 --- a/gemfiles/rails_5_no_sprockets.gemfile +++ b/gemfiles/rails_5_no_sprockets.gemfile @@ -1,5 +1,4 @@ # This file was generated by Appraisal -# This shouldn't have turbolinks or sprockets source "http://rubygems.org" diff --git a/gemfiles/rails_5_no_sprockets_webpacker.gemfile b/gemfiles/rails_5_no_sprockets_webpacker.gemfile index a424771dc..fb14d2b3b 100644 --- a/gemfiles/rails_5_no_sprockets_webpacker.gemfile +++ b/gemfiles/rails_5_no_sprockets_webpacker.gemfile @@ -1,10 +1,9 @@ # This file was generated by Appraisal -# This file shouldn't have turbolinks or sprockets in it source "http://rubygems.org" gem "rails", "~> 5.0.0" -gem "webpacker", :github => "rails/webpacker" +gem "webpacker", "< 3.0" gem "therubyracer" gemspec :path => "../" diff --git a/test/generators/coffee_component_generator_test.rb b/test/generators/coffee_component_generator_test.rb index c64342b17..089240369 100644 --- a/test/generators/coffee_component_generator_test.rb +++ b/test/generators/coffee_component_generator_test.rb @@ -19,20 +19,20 @@ def class_name 'GeneratedComponent' end - test 'that it the uses CoffeeScript syntax' do + def test_that_it_the_uses_CoffeeScript_syntax run_generator %w(GeneratedComponent name --coffee) assert_file filename, /^class @#{class_name}\sextends\sReact\.Component/ end - test 'that propTypes get assigned' do + def test_that_propTypes_get_assigned run_generator %w(GeneratedComponent name --coffee) assert_file filename, /@propTypes\s=/ assert_file filename, /React.PropTypes/ end - test 'that it generates working jsx' do + def test_that_it_generates_working_jsx expected_name_div = /React\.createElement\(\s*"div",\s*null,\s*"Name:\s*",\s*this\.props\.name\s*\)/x expected_shape_div = /React\.createElement\(\s*"div",\s*null,\s*"Address:\s*",\s*this\.props\.address\s*\)/x diff --git a/test/generators/component_generator_test.rb b/test/generators/component_generator_test.rb index efa6bd64a..afc071b25 100644 --- a/test/generators/component_generator_test.rb +++ b/test/generators/component_generator_test.rb @@ -16,7 +16,7 @@ def filename end end - test "creates the component file" do + def test_creates_the_component_file run_generator %w(GeneratedComponent) assert_file filename do |contents| @@ -27,12 +27,12 @@ def filename end end - test "creates the component file with a node argument" do + def test_creates_the_component_file_with_a_node_argument run_generator %w(GeneratedComponent name) assert_file filename, %r{name: React.PropTypes.node} end - test "creates the component file with various standard proptypes" do + def test_creates_the_component_file_with_various_standard_proptypes proptypes = %w(string bool number array func number object any) run_generator %w(GeneratedComponent) + proptypes.map { |type| "my_#{type}:#{type}" } proptypes.each do |type| @@ -40,24 +40,24 @@ def filename end end - test "creates a component file with an instanceOf property" do + def test_creates_a_component_file_with_an_instanceOf_property run_generator %w(GeneratedComponent favorite_food:instanceOf{food}) assert_file filename, /favoriteFood: React.PropTypes.instanceOf\(Food\)/ end - test "creates a component file with a oneOf property" do + def test_creates_a_component_file_with_a_oneOf_property run_generator %w(GeneratedComponent favorite_food:oneOf{pizza,hamburgers}) assert_file filename, /favoriteFood: React.PropTypes.oneOf\(\['pizza','hamburgers'\]\)/ end - test "creates a component file with a oneOfType property" do + def test_creates_a_component_file_with_a_oneOfType_property run_generator %w(GeneratedComponent favorite_food:oneOfType{string,Food}) expected_property = "favoriteFood: React.PropTypes.oneOfType([React.PropTypes.string,React.PropTypes.instanceOf(Food)])" assert_file filename, Regexp.new(Regexp.quote(expected_property)) end - test "generates working jsx" do + def test_generates_working_jsx expected_name_div = /React\.createElement\(\s*"div",\s*null,\s*\"Name:\s*\",\s*this\.props\.name\s*\)/x expected_shape_div = /React\.createElement\(\s*"div",\s*null,\s*\"Address:\s*\",\s*this\.props\.address\s*\)/x diff --git a/test/generators/es6_component_generator_test.rb b/test/generators/es6_component_generator_test.rb index 3c53d905b..ccc131214 100644 --- a/test/generators/es6_component_generator_test.rb +++ b/test/generators/es6_component_generator_test.rb @@ -20,19 +20,19 @@ def class_name 'GeneratedComponent' end - test "uses es6 syntax" do + def test_uses_es6_syntax run_generator %w(GeneratedComponent name --es6) assert_file filename, /^class\s#{class_name}\sextends\sReact\.Component/ end - test "assigns defaultProps after class definintion" do + def test_assigns_defaultProps_after_class_definintion run_generator %w(GeneratedComponent name --es6) assert_file filename, /\s^#{class_name}\.propTypes/ end - test "generates working jsx" do + def test_generates_working_jsx expected_name_div = /React\.createElement\(\s*"div",\s*null,\s*\"Name:\s*\",\s*this\.props\.name\s*\)/x expected_shape_div = /React\.createElement\(\s*"div",\s*null,\s*\"Address:\s*\",\s*this\.props\.address\s*\)/x diff --git a/test/generators/install_generator_sprockets_test.rb b/test/generators/install_generator_sprockets_test.rb index cf3f0febe..efc259018 100644 --- a/test/generators/install_generator_sprockets_test.rb +++ b/test/generators/install_generator_sprockets_test.rb @@ -16,18 +16,18 @@ def copy_directory(dir) FileUtils.cp_r source, dest end - test "adds requires to `application.js`" do + def test_adds_requires_to_application_js run_generator assert_application_file_created end - test "it modifes an existing 'application.js'" do + def test_it_modifes_an_existing_application_js copy_directory('app/assets/javascripts/application.js') run_generator assert_application_file_modified end - test "creates `application.js` if it doesn't exist" do + def test_creates_application_js_if_it_doesnt_exist copy_directory('app/assets/javascripts/application.js') File.delete destination_root + '/app/assets/javascripts/application.js' @@ -35,14 +35,14 @@ def copy_directory(dir) assert_application_file_created end - test "modifies `application.js` if it's empty" do + def test_modifies_application_js_if_its_empty init_application_js '' run_generator assert_application_file_created end - test "updates `application.js` if require_tree is commented" do + def test_updates_application_js_if_require_tree_is_commented init_application_js <<-END // // require_tree . @@ -53,7 +53,7 @@ def copy_directory(dir) assert_application_file_modified end - test "updates `application.js` if require turbolinks has extra spaces" do + def test_updates_application_js_if_require_turbolinks_has_extra_spaces init_application_js <<-END // //#{"= require turbolinks "} @@ -64,20 +64,20 @@ def copy_directory(dir) assert_application_file_modified end - test "creates server_rendering.js with default requires" do + def test_creates_server_rendering_js_with_default_requires run_generator server_rendering_file_path = "app/assets/javascripts/server_rendering.js" assert_file server_rendering_file_path, %r{//= require react-server\n} assert_file server_rendering_file_path, %r{//= require ./components\n} end - test "creates server rendering initializer" do + def test_creates_server_rendering_initializer run_generator initializer_path = "config/initializers/react_server_rendering.rb" assert_file(initializer_path, %r{Rails.application.config.assets.precompile \+= \["server_rendering.js"\]}) end - test "skipping server rendering" do + def test_skipping_server_rendering run_generator %w(--skip-server-rendering) assert_no_file "config/initializers/react_server_rendering.rb" assert_no_file "app/assets/javascripts/server_rendering.js" diff --git a/test/generators/install_generator_webpacker_test.rb b/test/generators/install_generator_webpacker_test.rb index ab7b39b9f..7ea3dbd57 100644 --- a/test/generators/install_generator_webpacker_test.rb +++ b/test/generators/install_generator_webpacker_test.rb @@ -23,13 +23,13 @@ def copy_directory(dir) FileUtils.cp_r source, dest end - test "adds requires to `application.js`" do + def test_adds_requires_to_application_js run_generator assert_file "app/javascript/packs/application.js", EXPECTED_SETUP assert_file "app/javascript/components" end - test "creates server_rendering.js with default requires" do + def test_creates_server_rendering_js_with_default_requires run_generator assert_file DEFAULT_SERVER_RENDERING_PACK_PATH do |contents| assert_includes contents, "var componentRequireContext = require.context(\"components\", true)\n" @@ -38,7 +38,7 @@ def copy_directory(dir) end end - test "skipping server rendering" do + def test_skipping_server_rendering run_generator %w(--skip-server-rendering) assert_no_file DEFAULT_SERVER_RENDERING_PACK_PATH end diff --git a/test/react/jsx/jsx_prepocessor_test.rb b/test/react/jsx/jsx_prepocessor_test.rb index 321b08485..9e4b61efc 100644 --- a/test/react/jsx/jsx_prepocessor_test.rb +++ b/test/react/jsx/jsx_prepocessor_test.rb @@ -6,7 +6,7 @@ class JSXPreprocessorTest < ActiveSupport::TestCase REQUIRED_COFFEESCRIPT = "var requireCoffee; requireCoffee = true;" REQUIRED_JSX = "React.createElement(\"div\", { className: \"require-jsx\" });" OWN_JSX = "React.createElement(\"div\", { className: \"le-javascript\" });" - test 'executes //= require directives' do + def test_executes_require_directives require_parent = SprocketsHelpers.fetch_asset_body("require_test/jsx_preprocessor_test.js") assert_compiled_javascript_includes(require_parent, REQUIRED_JAVASCRIPT) diff --git a/test/react/jsx/jsx_transformer_test.rb b/test/react/jsx/jsx_transformer_test.rb index 757454d83..637a4f153 100644 --- a/test/react/jsx/jsx_transformer_test.rb +++ b/test/react/jsx/jsx_transformer_test.rb @@ -13,7 +13,7 @@ class JSXTransformerTest < ActionDispatch::IntegrationTest SprocketsHelpers.manually_expire_asset('JSXTransformer.js') end - test 'can use dropped-in version of JSX transformer' do + def test_can_use_dropped_in_version_of_JSX_transformer hidden_path = Rails.root.join("vendor/assets/react/JSXTransformer__.js") replacing_path = Rails.root.join("vendor/assets/react/JSXTransformer.js") @@ -27,7 +27,7 @@ class JSXTransformerTest < ActionDispatch::IntegrationTest assert_equal 'test_confirmation_token_jsx_transformed;', @response.body.strip end - test 'accepts harmony: true option' do + def test_accepts_harmony_true_option React::JSX.transform_options = {harmony: true} get '/assets/harmony_example.js' assert_response :success @@ -37,14 +37,14 @@ class JSXTransformerTest < ActionDispatch::IntegrationTest assert_match(/active=\$__0\.active/, @response.body, "destructuring assignment") end - test 'accepts strip_types: true option' do + def test_accepts_strip_types_true_option React::JSX.transform_options = {strip_types: true, harmony: true} get '/assets/flow_types_example.js' assert_response :success assert_match(/\(i\s*,\s*name\s*\)\s*\{/, @response.body, "type annotations are removed") end - test 'accepts asset_path: option' do + def test_accepts_asset_path_option hidden_path = Rails.root.join("vendor/assets/react/JSXTransformer__.js") custom_path = Rails.root.join("vendor/assets/react/custom") replacing_path = custom_path.join("CustomTransformer.js") diff --git a/test/react/jsx_test.rb b/test/react/jsx_test.rb index db6270be9..6962ef299 100644 --- a/test/react/jsx_test.rb +++ b/test/react/jsx_test.rb @@ -36,21 +36,21 @@ class JSXTransformTest < ActionDispatch::IntegrationTest reset_transformer end - test 'asset pipeline should transform JSX' do + def test_asset_pipeline_should_transform_JSX SprocketsHelpers.manually_expire_asset('example.js') get '/assets/example.js' assert_response :success assert_compiled_javascript_matches(EXPECTED_JS, @response.body) end - test 'asset pipeline should transform JSX + Coffeescript' do + def test_asset_pipeline_should_transform_JSX_and_Coffeescript SprocketsHelpers.manually_expire_asset('example2.js') get '/assets/example2.js' assert_response :success assert_compiled_javascript_matches(EXPECTED_JS_2, @response.body) end - test 'use a custom transformer' do + def test_use_a_custom_transformer React::JSX.transformer_class = NullTransformer SprocketsHelpers.manually_expire_asset('example2.js') get '/assets/example2.js' diff --git a/test/react/rails/asset_variant_test.rb b/test/react/rails/asset_variant_test.rb index 29e2e8bb8..f0b0b8f63 100644 --- a/test/react/rails/asset_variant_test.rb +++ b/test/react/rails/asset_variant_test.rb @@ -5,7 +5,7 @@ def build_variant(options) React::Rails::AssetVariant.new(options) end - test 'it points to different directories for react' do + def test_it_points_to_different_directories_for_react production_variant = build_variant(variant: :production) assert_match(%r{/lib/assets/react-source/production}, production_variant.react_directory) @@ -13,12 +13,12 @@ def build_variant(options) assert_match(%r{/lib/assets/react-source/development}, development_variant.react_directory) end - test 'points to jsx transformer' do + def test_points_to_jsx_transformer variant = build_variant({}) assert_match(%r{/lib/assets/javascripts/}, variant.jsx_directory) end - test 'it includes addons if requested' do + def test_it_includes_addons_if_requested asset_variant = build_variant(addons: true) assert_equal "development-with-addons", asset_variant.react_build end diff --git a/test/react/rails/component_mount_test.rb b/test/react/rails/component_mount_test.rb index e2da64482..6696ed2cd 100644 --- a/test/react/rails/component_mount_test.rb +++ b/test/react/rails/component_mount_test.rb @@ -11,7 +11,7 @@ class ComponentMountTest < ActionDispatch::IntegrationTest @helper = React::Rails::ComponentMount.new end - test '#react_component accepts React props' do + def test_react_component_accepts_React_props html = @helper.react_component('Foo', {bar: 'value'}) expected_props = %w(data-react-class="Foo" data-react-props="{"bar":"value"}") expected_props.each do |segment| @@ -19,7 +19,7 @@ class ComponentMountTest < ActionDispatch::IntegrationTest end end - test '#react_component accepts React props with camelize_props' do + def test_react_component_accepts_React_props_with_camelize_props React::Rails::ComponentMount.camelize_props_switch = true helper = React::Rails::ComponentMount.new html = helper.react_component('Foo', {foo_bar: 'value'}) @@ -29,7 +29,7 @@ class ComponentMountTest < ActionDispatch::IntegrationTest end end - test '#react_component allows camelize_props to be passed in as an option' do + def test_react_component_allows_camelize_props_to_be_passed_in_as_an_option React::Rails::ComponentMount.camelize_props_switch = false helper = React::Rails::ComponentMount.new html = helper.react_component('Foo', {foo_bar: 'value'}, camelize_props: true) @@ -47,7 +47,7 @@ class ComponentMountTest < ActionDispatch::IntegrationTest end end - test '#react_component accepts React props with camelize_props containing nested arrays' do + def test_react_component_accepts_React_props_with_camelize_props_containing_nested_arrays React::Rails::ComponentMount.camelize_props_switch = true helper = React::Rails::ComponentMount.new html = helper.react_component('Foo', {foo_bar: [{user_name: 'Ryan'}, {user_name: 'Matt'}], bar_foo: 1}) @@ -57,7 +57,7 @@ class ComponentMountTest < ActionDispatch::IntegrationTest end end - test '#react_component accepts jbuilder-based strings as properties' do + def test_react_component_accepts_jbuilder_based_strings_as_properties jbuilder_json = Jbuilder.new do |json| json.bar 'value' end.target! @@ -69,25 +69,25 @@ class ComponentMountTest < ActionDispatch::IntegrationTest end end - test '#react_component accepts string props with prerender: true' do + def test_react_component_accepts_string_props_with_prerender_true html = @helper.react_component('Todo', {todo: 'render on the server'}.to_json, prerender: true) assert(html.include?('data-react-class="Todo"'), "it includes attrs for UJS") assert(html.include?('>render on the server'), "it includes rendered HTML") assert(html.include?('data-reactid'), "it includes React properties") end - test '#react_component passes :static to BundleRenderer' do + def test_react_component_passes_static_to_BundleRenderer html = @helper.react_component('Todo', {todo: 'render on the server'}.to_json, prerender: :static) assert(html.include?('>render on the server'), "it includes rendered HTML") assert(!html.include?('data-reactid'), "it DOESNT INCLUDE React properties") end - test '#react_component does not include HTML properties with a static render' do + def test_react_component_does_not_include_HTML_properties_with_a_static_render html = @helper.react_component('Todo', {todo: 'render on the server'}.to_json, prerender: :static) assert_equal('
  • render on the server
  • ', html) end - test '#react_component accepts HTML options and HTML tag' do + def test_react_component_accepts_HTML_options_and_HTML_tag assert @helper.react_component('Foo', {}, :span).match(/<\/span>/) html = @helper.react_component('Foo', {}, {class: 'test', tag: :span, data: {foo: 1}}) @@ -108,7 +108,7 @@ def self.react_rails_prerenderer end end - test "it uses the controller's react_rails_prerenderer, if available" do + def test_it_uses_the_controllers_react_rails_prerenderer_if_available @helper.setup(DummyController) rendered_component = @helper.react_component('Foo', {"ok" => true}, prerender: :static) assert_equal %|
    rendered Foo with {"ok":true}
    |, rendered_component diff --git a/test/react/rails/controller_lifecycle_test.rb b/test/react/rails/controller_lifecycle_test.rb index eb1d61a34..302aa7686 100644 --- a/test/react/rails/controller_lifecycle_test.rb +++ b/test/react/rails/controller_lifecycle_test.rb @@ -37,20 +37,20 @@ def teardown React::Rails::ViewHelper.helper_implementation_class = @previous_helper_implementation end - test "it creates a helper object and puts it in the request env" do + def test_it_creates_a_helper_object_and_puts_it_in_the_request_env get '/pages/1' helper_obj = controller.__react_component_helper assert(helper_obj.is_a?(DummyHelperImplementation), "It uses the view helper implementation class") end - test "it calls setup and teardown methods" do + def test_it_calls_setup_and_teardown_methods get '/pages/1?param_test=123' helper_obj = controller.__react_component_helper lifecycle_steps = ["123", :react_component, :react_component, :teardown] assert_equal(lifecycle_steps, helper_obj.events) end - test "there's a new helper object for every request" do + def test_theres_a_new_helper_object_for_every_request get '/pages/1' first_helper = controller.__react_component_helper get '/pages/1' diff --git a/test/react/rails/pages_controller_test.rb b/test/react/rails/pages_controller_test.rb index 65c195888..90ef64cee 100644 --- a/test/react/rails/pages_controller_test.rb +++ b/test/react/rails/pages_controller_test.rb @@ -6,7 +6,7 @@ class PagesControllerTest < ActionController::TestCase WebpackerHelpers.compile_if_missing end - test 'renders successfully' do + def test_renders_successfully get :show, query_params(id: 1) assert_equal(200, response.status) end diff --git a/test/react/rails/railtie_test.rb b/test/react/rails/railtie_test.rb index f943dd140..5e57047c4 100644 --- a/test/react/rails/railtie_test.rb +++ b/test/react/rails/railtie_test.rb @@ -1,7 +1,7 @@ require "test_helper" class RailtieTest < ActionDispatch::IntegrationTest - test "reloaders are configured after initializers are loaded" do + def test_reloaders_are_configured_after_initializers_are_loaded @test_file = File.expand_path("../../dummy/app/pants/yfronts.js", File.dirname(__FILE__)) FileUtils.touch @test_file results = Dummy::Application.reloaders.map(&:updated?) diff --git a/test/react/rails/react_rails_ujs_test.rb b/test/react/rails/react_rails_ujs_test.rb index a55e1567a..92c946ed2 100644 --- a/test/react/rails/react_rails_ujs_test.rb +++ b/test/react/rails/react_rails_ujs_test.rb @@ -32,7 +32,7 @@ def refute_greeting(page, greeting) assert_greeting(page, greeting, refute: true) end - test 'ujs object present on the global React object and has our methods' do + def test_ujs_object_present_on_the_global_React_object_and_has_our_methods visit '/pages/1' assert_greeting(page, 'Hello Bob') @@ -55,7 +55,7 @@ def refute_greeting(page, greeting) assert_equal(unmount_components_present, true) end - test 'react_ujs works with rendered HTML' do + def test_react_ujs_works_with_rendered_HTML visit '/pages/1' assert_greeting(page, 'Hello Bob') @@ -64,7 +64,7 @@ def refute_greeting(page, greeting) assert_greeting(page, 'Goodbye Bob') end - test 'react_ujs works with Turbolinks' do + def test_react_ujs_works_with_Turbolinks visit '/pages/1' assert_greeting(page, 'Hello Bob') assert page.evaluate_script("Turbolinks.supported") @@ -102,7 +102,7 @@ def refute_greeting(page, greeting) assert_greeting(page, 'Hello Bob') end - test 'react_ujs can unmount/mount using a selector reference for a component parent' do + def test_react_ujs_can_unmount_and_mount_using_a_selector_reference_for_a_component_parent visit '/pages/1' assert_greeting(page, 'Hello Bob') @@ -113,7 +113,7 @@ def refute_greeting(page, greeting) assert_greeting(page, 'Hello Bob') end - test 'react_ujs can unmount/mount using a selector reference for the component' do + def test_react_ujs_can_unmount_and_mount_using_a_selector_reference_for_the_component visit '/pages/1' assert_greeting(page, 'Hello Bob') @@ -124,7 +124,7 @@ def refute_greeting(page, greeting) assert_greeting(page, 'Hello Bob') end - test 'react_ujs does not unmount components that do not match a selector reference for the component' do + def test_react_ujs_does_not_unmount_components_that_do_not_match_a_selector_reference_for_the_component visit '/pages/1' assert_greeting page, 'Hello Bob' assert page.has_content?('Another Component'), page.body @@ -139,7 +139,7 @@ def refute_greeting(page, greeting) end - test 'react_ujs can unmount/mount using a dom node context' do + def test_react_ujs_can_unmount_and_mount_using_a_dom_node_context visit '/pages/1' assert_greeting(page, 'Hello Bob') @@ -150,13 +150,13 @@ def refute_greeting(page, greeting) assert_greeting(page, 'Hello Bob') end - test 'react server rendering also gets mounted on client' do + def test_react_server_rendering_also_gets_mounted_on_client visit '/server/1' assert_match(/data-react-class=\"TodoList\"/, page.html) assert_match(/yep/, page.find("#status").text) end - test 'react server rendering does not include internal properties' do + def test_react_server_rendering_does_not_include_internal_properties visit '/server/1' assert_no_match(/tag=/, page.html) assert_no_match(/prerender=/, page.html) diff --git a/test/react/rails/view_helper_test.rb b/test/react/rails/view_helper_test.rb index e8ff78e7a..42a2fcdc7 100644 --- a/test/react/rails/view_helper_test.rb +++ b/test/react/rails/view_helper_test.rb @@ -9,13 +9,13 @@ class ViewHelperHelper end class ViewHelperTest < ActionView::TestCase - test "view helper can be called directly" do + def test_view_helper_can_be_called_directly expected_html = %{
    } rendered_html = ViewHelperHelper.react_component("Component", {a: "b"}) assert_equal(expected_html, rendered_html) end - test 'view helper accepts block usage' do + def test_view_helper_accepts_block_usage expected_html = %{
    content
    } rendered_html = ViewHelperHelper.react_component("Component", {a: "b"}) do "content" @@ -23,13 +23,13 @@ class ViewHelperTest < ActionView::TestCase assert_equal(expected_html, rendered_html) end - test "view helper can be used in stand-alone views" do + def test_view_helper_can_be_used_in_stand_alone_views @name = "React-Rails" render template: "pages/show" assert_includes(rendered, "React-Rails") end - test "view helper can accept block and render inner content only once" do + def test_view_helper_can_accept_block_and_render_inner_content_only_once rendered_html = render partial: "pages/component_with_inner_html" expected_html = < @@ -40,7 +40,7 @@ class ViewHelperTest < ActionView::TestCase end - test "view helper uses the implementation class set in the initializer" do + def test_view_helper_uses_the_implementation_class_set_in_the_initializer assert_equal( React::Rails::ViewHelper.helper_implementation_class.to_s, "CustomComponentMount" diff --git a/test/react/rails/webpacker_test.rb b/test/react/rails/webpacker_test.rb index 15e440777..cb4316346 100644 --- a/test/react/rails/webpacker_test.rb +++ b/test/react/rails/webpacker_test.rb @@ -14,7 +14,7 @@ class ReactRailsWebpackerTest < ActionDispatch::IntegrationTest WebpackerHelpers.clear_webpacker_packs end - test 'it mounts components from the pack' do + def test_it_mounts_components_from_the_pack visit '/pack_component' assert page.has_content?('Export Default') assert page.has_content?('Named Export') diff --git a/test/react/server_rendering/bundle_renderer_test.rb b/test/react/server_rendering/bundle_renderer_test.rb index cf0bc710a..76ad05e7b 100644 --- a/test/react/server_rendering/bundle_renderer_test.rb +++ b/test/react/server_rendering/bundle_renderer_test.rb @@ -30,24 +30,24 @@ class BundleRendererTest < ActiveSupport::TestCase end end - test '#render returns HTML' do + def test_render_returns_HTML result = @renderer.render("Todo", {todo: "write tests"}, nil) assert_match(//, result) assert_match(/data-react-checksum/, result) end - test '#render accepts strings' do + def test_render_accepts_strings result = @renderer.render("Todo", {todo: "write more tests"}.to_json, nil) assert_match(//, result) end - test '#render accepts :static pre-render option' do + def test_render_accepts_static_pre_render_option result = @renderer.render("Todo", {todo: "write more tests"}, :static) assert_match(/
  • write more tests<\/li>/, result) assert_no_match(/data-react-checksum/, result) end - test '#render replays console messages' do + def test_render_replays_console_messages result = @renderer.render("TodoListWithConsoleLog", {todos: ["log some messages"]}, nil) assert_match(/ HTML - test "it clears the state between each request" do + def test_it_clears_the_state_between_each_request # Each request should only contain one log: get '/server/1' assert_includes(response.body, EXPECTED_REPLAY) diff --git a/test/react/server_rendering/exec_js_renderer_test.rb b/test/react/server_rendering/exec_js_renderer_test.rb index f45f881e7..a92dc1ee1 100644 --- a/test/react/server_rendering/exec_js_renderer_test.rb +++ b/test/react/server_rendering/exec_js_renderer_test.rb @@ -21,19 +21,19 @@ class ExecJSRendererTest < ActiveSupport::TestCase @renderer = React::ServerRendering::ExecJSRenderer.new(code: code) end - test '#render returns HTML' do + def test_render_returns_HTML result = @renderer.render("Todo", {todo: "write tests"}.to_json, {}) assert_match(//, result) assert_match(/data-react-checksum/, result) end - test '#render accepts render_function:' do + def test_render_accepts_render_function result = @renderer.render("Todo", {todo: "write more tests"}.to_json, render_function: "renderToStaticMarkup") assert_match(/
  • write more tests<\/li>/, result) assert_no_match(/data-react-checksum/, result) end - test '#before_render is called before #after_render' do + def test_before_render_is_called_before_after_render def @renderer.before_render(name, props, opts) "throw 'before_render ' + afterRenderVar" end @@ -50,7 +50,7 @@ def @renderer.after_render(name, props, opts) assert_no_match(/assigned_after_render/, error.message) end - test '#after_render is called after #before_render' do + def test_after_render_is_called_after_before_render def @renderer.before_render(name, props, opts) "var beforeRenderVar = 'assigned_before_render'" end @@ -67,7 +67,7 @@ def @renderer.after_render(name, props, opts) assert_match(/assigned_before_render/, error.message) end - test '.new accepts code:' do + def test_new_accepts_code dummy_renderer = React::ServerRendering::ExecJSRenderer.new(code: DUMMY_IMPLEMENTATION) result = dummy_renderer.render("Todo", {todo: "get a real job"}.to_json, {}) assert_equal("serverRender was called", result) diff --git a/test/react/server_rendering/webpacker_manifest_container_test.rb b/test/react/server_rendering/webpacker_manifest_container_test.rb index cb8357351..7f8bcf8f7 100644 --- a/test/react/server_rendering/webpacker_manifest_container_test.rb +++ b/test/react/server_rendering/webpacker_manifest_container_test.rb @@ -7,7 +7,7 @@ class WebpackerManifestContainerTest < ActiveSupport::TestCase WebpackerHelpers.clear_webpacker_packs end - test "it loads JS from the webpacker container" do + def test_it_loads_JS_from_the_webpacker_container WebpackerHelpers.compile container = React::ServerRendering::WebpackerManifestContainer.new js_file = container.find_asset("application.js") diff --git a/test/react/server_rendering_test.rb b/test/react/server_rendering_test.rb index c7c1a3ac1..4131cf962 100644 --- a/test/react/server_rendering_test.rb +++ b/test/react/server_rendering_test.rb @@ -26,13 +26,13 @@ class ReactServerRenderingTest < ActiveSupport::TestCase React::ServerRendering.reset_pool end - test '.render returns a rendered string' do + def test_render_returns_a_rendered_string props = {"props" => true} result = React::ServerRendering.render("MyComponent", props, "prerender-opts") assert_equal("TEST rendered MyComponent with #{props} and prerender-opts", result) end - test '.reset_pool forgets old renderers' do + def test_reset_pool_forgets_old_renderers # At first, they use the first options: assert_match(/^TEST/, React::ServerRendering.render(nil, nil, nil)) assert_match(/^TEST/, React::ServerRendering.render(nil, nil, nil)) diff --git a/test/react_asset_test.rb b/test/react_asset_test.rb index b868bdc46..b554d9236 100644 --- a/test/react_asset_test.rb +++ b/test/react_asset_test.rb @@ -10,7 +10,7 @@ class ReactAssetTest < ActionDispatch::IntegrationTest SprocketsHelpers.clear_sprockets_cache end - test 'asset pipeline should deliver drop-in react file replacement' do + def test_asset_pipeline_should_deliver_drop_in_react_file_replacement app_react_file_path = File.expand_path("../dummy/vendor/assets/javascripts/react.js", __FILE__) react_file_token = "'test_confirmation_token_react_content_non_production';\n" File.write(app_react_file_path, react_file_token) @@ -26,7 +26,7 @@ class ReactAssetTest < ActionDispatch::IntegrationTest assert_equal react_file_token.length, @response.body.length, "The asset route serves the drop-in file" end - test 'precompiling assets works' do + def test_precompiling_assets_works begin SprocketsHelpers.precompile_assets ensure @@ -34,7 +34,7 @@ class ReactAssetTest < ActionDispatch::IntegrationTest end end - test "the development version with addons is loaded" do + def test_the_development_version_with_addons_is_loaded asset = Rails.application.assets.find_asset('react') path = if asset.respond_to?(:pathname) @@ -47,7 +47,7 @@ class ReactAssetTest < ActionDispatch::IntegrationTest assert path.end_with?('development-with-addons/react.js') end - test "the production build is optimized for production" do + def test_the_production_build_is_optimized_for_production production_path = File.expand_path("../../lib/assets/react-source/production/react.js", __FILE__) production_js = File.read(production_path) env_checks = production_js.scan("NODE_ENV") diff --git a/test/server_rendered_html_test.rb b/test/server_rendered_html_test.rb index 16dfcfb39..48de5f1b9 100644 --- a/test/server_rendered_html_test.rb +++ b/test/server_rendered_html_test.rb @@ -16,7 +16,7 @@ def wait_to_ensure_asset_pipeline_detects_changes end end - test 'react server rendering reloads jsx after changes to the jsx files' do + def test_react_server_rendering_reloads_jsx_after_changes_to_the_jsx_files if WebpackerHelpers.available? file_with_updates = File.expand_path('../helper_files/TodoListWithUpdates.js', __FILE__) file_without_updates = File.expand_path('../helper_files/TodoListWithoutUpdates.js', __FILE__) @@ -53,7 +53,7 @@ def wait_to_ensure_asset_pipeline_detects_changes end end - test 'it reloads when new jsx files are added to the asset pipeline' do + def test_it_reloads_when_new_jsx_files_are_added_to_the_asset_pipeline begin assert_raises(ActionView::Template::Error) { get '/server/1?component_name=NewList' @@ -61,15 +61,15 @@ def wait_to_ensure_asset_pipeline_detects_changes if WebpackerHelpers.available? new_file_path = '../dummy/app/javascript/components/NewList.js' - new_file_contents = <<-JS + new_file_contents = <<-JSDOC var React = require("react") module.exports = function() { return "New List" } - JS + JSDOC else new_file_path = '../dummy/app/assets/javascripts/components/ZZ_NewComponent.js.jsx' - new_file_contents = <<-JS + new_file_contents = <<-JSDOC var NewList = function() { return "New List" } - JS + JSDOC end new_file_path = File.expand_path(new_file_path, __FILE__) @@ -89,7 +89,7 @@ def wait_to_ensure_asset_pipeline_detects_changes end end - test 'react server rendering shows console output as html comment' do + def test_react_server_rendering_shows_console_output_as_html_comment # Make sure console messages are replayed when requested React::ServerRendering.renderer_options = {replay_console: true} React::ServerRendering.reset_pool @@ -110,7 +110,7 @@ def wait_to_ensure_asset_pipeline_detects_changes assert_no_match(/console.error/, response.body) end - test 'react inline component rendering (pre-rendered)' do + def test_react_inline_component_rendering_pre_rendered get '/server/inline_component_prerender_true' rendered_html = response.body assert_match(/