├── .coveralls.yml ├── .gitignore ├── .rspec ├── .travis.yml ├── Gemfile ├── README.md ├── Rakefile ├── app ├── assets │ └── javascripts │ │ └── js-namespace-rails.js └── views │ └── js_namespace_rails │ ├── _hook.js.erb │ ├── _init.js.erb │ └── _initialize_script.html.erb ├── bin ├── console └── setup ├── js-namespace-rails.gemspec ├── lib ├── js-namespace-rails.rb ├── js_namespace_rails.rb └── js_namespace_rails │ ├── action_controller_extension.rb │ ├── action_view │ └── helpers │ │ └── asset_tag_helper.rb │ ├── engine.rb │ └── version.rb └── spec ├── dummy ├── README.rdoc ├── Rakefile ├── app │ ├── assets │ │ ├── images │ │ │ └── .keep │ │ ├── javascripts │ │ │ ├── application.js │ │ │ └── users.es6 │ │ └── stylesheets │ │ │ └── application.css │ ├── controllers │ │ ├── application_controller.rb │ │ ├── concerns │ │ │ └── .keep │ │ └── users_controller.rb │ ├── helpers │ │ └── application_helper.rb │ ├── mailers │ │ └── .keep │ ├── models │ │ ├── .keep │ │ └── concerns │ │ │ └── .keep │ └── views │ │ ├── layouts │ │ ├── application.html.erb │ │ └── frontend.html.erb │ │ └── users │ │ ├── index.html.erb │ │ ├── new.html.erb │ │ └── show.js.erb ├── bin │ ├── bundle │ ├── rails │ ├── rake │ └── setup ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── database.yml │ ├── environment.rb │ ├── environments │ │ ├── development.rb │ │ ├── production.rb │ │ └── test.rb │ ├── initializers │ │ ├── assets.rb │ │ ├── backtrace_silencers.rb │ │ ├── cookies_serializer.rb │ │ ├── filter_parameter_logging.rb │ │ ├── inflections.rb │ │ ├── mime_types.rb │ │ ├── session_store.rb │ │ └── wrap_parameters.rb │ ├── locales │ │ └── en.yml │ ├── routes.rb │ └── secrets.yml ├── lib │ └── assets │ │ └── .keep ├── log │ └── .keep └── public │ ├── 404.html │ ├── 422.html │ ├── 500.html │ └── favicon.ico ├── js_namepsace_rails_spec.rb └── spec_helper.rb /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | /js-namespace-rails/ 11 | .idea/ 12 | .DS_Store 13 | #.travis.yml 14 | *.gem 15 | *.un~ 16 | /spec/dummy/tmp/ 17 | /spec/dummy/log/ 18 | .ruby-version 19 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.1.5 4 | - 2.2 5 | - 2.3.0 6 | script: xvfb-run rspec 7 | before_install: gem install bundler -v 1.11.2 8 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in js-namespace-rails.gemspec 4 | gemspec 5 | 6 | group :test do 7 | gem 'jquery-rails' 8 | gem "sprockets-es6" 9 | end 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JsNamespaceRails [![Build Status](https://travis-ci.org/falm/js-namespace-rails.svg?branch=master)](https://travis-ci.org/falm/js-namespace-rails) [![Coverage Status](https://coveralls.io/repos/github/falm/js-namespace-rails/badge.svg?branch=master)](https://coveralls.io/github/falm/js-namespace-rails?branch=master) [![Code Climate](https://codeclimate.com/github/falm/js-namespace-rails/badges/gpa.svg)](https://codeclimate.com/github/falm/js-namespace-rails) [![Dependency Status](https://gemnasium.com/badges/github.com/falm/js-namespace-rails.svg)](https://gemnasium.com/github.com/falm/js-namespace-rails) [![Gem Version](https://badge.fury.io/rb/js-namespace-rails.svg)](https://badge.fury.io/rb/js-namespace-rails) 2 | 3 | 4 | Rails's asset pipeline compiles all of js file into a single file which is executed on all pages. 5 | There has a problem, some time we want to execute selective code on specific page, but asset pipeline doesn't support. 6 | js-namespace-rails can handle this problem by using it's method to namespace and selectively execute certain javascript depending on which Rails controller action is active. 7 | 8 | ## Installation 9 | 10 | Add this line to your application's Gemfile: 11 | 12 | ```ruby 13 | gem 'js-namespace-rails' 14 | ``` 15 | 16 | ## Setup 17 | 18 | Require js-namespace-rails file in application.js or other main file, 19 | **notice** js-namespace-rails has no dependency 20 | 21 | ``` js 22 | 23 | //= require js-namespace-rails 24 | 25 | ``` 26 | 27 | 28 | ## Usage 29 | Assume your project have articles_controller 30 | ``` ruby 31 | class ArticlesController < ApplicationController 32 | def index 33 | end 34 | end 35 | ``` 36 | And its corresponding js file app/assets/javascripts/articles.js.erb 37 | 38 | then you just need to write below into the js file 39 | ``` js 40 | // app/assets/javascripts/articles.js.erb 41 | JsSpace.on('articles', { 42 | init: function(){ 43 | console.log('common logic of article in here'); 44 | }, 45 | index: function(){ 46 | console.log('logic of index action in here'); 47 | } 48 | }); 49 | ``` 50 | 51 | ## Feature 52 | ### Passing Parameters to js 53 | ```ruby 54 | class ArticlesController < ApplicationController 55 | def show 56 | @article = Article.find(params[:id]) 57 | js author: @article.author 58 | # also you can passing an object 59 | js article: @article 60 | end 61 | end 62 | ``` 63 | 64 | ```js 65 | // app/assets/javascripts/articles.js.erb 66 | JsSpace.on('articles', { 67 | show: function(){ 68 | console.log(this.params.author); // get author from params 69 | console.log(this.params.article.title); // get title of article 70 | } 71 | }); 72 | ``` 73 | ## License 74 | MIT License. 75 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | -------------------------------------------------------------------------------- /app/assets/javascripts/js-namespace-rails.js: -------------------------------------------------------------------------------- 1 | 2 | (function(win){ 3 | 4 | 'use strict'; 5 | 6 | function JsNamespace(){ 7 | 8 | var self = this; 9 | 10 | self.INIT = 'init'; 11 | 12 | self.RESERVE = ['new']; 13 | 14 | self.controllerList = {}; 15 | 16 | self.on = function(controllerName, obj){ 17 | self.controllerList[controllerName] = obj; 18 | }; 19 | 20 | self.params = {}; 21 | 22 | self.fetchParams = function(){ 23 | return self.params; 24 | }; 25 | 26 | self.init = function(controllerName, actionName){ 27 | 28 | var params = self.fetchParams(); 29 | 30 | var activeController = self.controllerList[controllerName]; 31 | 32 | if( activeController !== undefined && typeof activeController === 'object') { 33 | 34 | activeController.params = params; 35 | 36 | if(activeController[self.INIT] !== undefined && typeof activeController[self.INIT] === 'function'){ 37 | activeController.init(params); 38 | } 39 | 40 | if(activeController[actionName] !== undefined && typeof activeController[actionName] === 'function'){ 41 | activeController[actionName].call(activeController, params); 42 | } else if ( self.RESERVE.indexOf(actionName) >= 0 && activeController['_' + actionName] !== undefined) { 43 | activeController['_' + actionName].call(activeController, params); 44 | } 45 | } 46 | }; 47 | 48 | self.ready = function(fn){ 49 | if ( typeof fn !== 'function' ) return; 50 | 51 | if ( document.readyState === 'complete' ) { 52 | return fn(); 53 | } 54 | 55 | document.addEventListener( 'interactive', fn, false ); 56 | } 57 | } 58 | 59 | var jsNamespace = new JsNamespace(); 60 | 61 | document.addEventListener('DOMContentLoaded', function(){ 62 | 63 | var $body = document.querySelector('body'); 64 | 65 | var controllerName = $body.getAttribute('data-controller'); 66 | 67 | var actionName = $body.getAttribute('data-action'); 68 | 69 | jsNamespace.init(controllerName, actionName) 70 | 71 | }); 72 | 73 | win.JsSpace = jsNamespace; 74 | 75 | })(this); 76 | -------------------------------------------------------------------------------- /app/views/js_namespace_rails/_hook.js.erb: -------------------------------------------------------------------------------- 1 | document.addEventListener('DOMContentLoaded', function() { 2 | document.body.setAttribute('data-controller', '<%= controller_path.gsub(/\//,'_') %>'); 3 | document.body.setAttribute('data-action', '<%= action_name %>'); 4 | if(window.JsSpace){ 5 | window.JsSpace.params = <%= raw @js_namespace_rails_params.to_json %>; 6 | } 7 | }); 8 | -------------------------------------------------------------------------------- /app/views/js_namespace_rails/_init.js.erb: -------------------------------------------------------------------------------- 1 | JsSpace.params = <%= raw @js_namespace_rails_params.to_json %>; 2 | 3 | JsSpace.init('<%= controller_path.gsub(/\//,'_')%>', '<%= action_name %>'); 4 | -------------------------------------------------------------------------------- /app/views/js_namespace_rails/_initialize_script.html.erb: -------------------------------------------------------------------------------- 1 | 2 | <% if request.headers["X-XHR-Referer"].present? %> 3 | 7 | <% end %> -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require 'js_namespace_rails' 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start 15 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | bundle install 6 | 7 | # Do any other automated setup that you need to do here 8 | -------------------------------------------------------------------------------- /js-namespace-rails.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'js_namespace_rails/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'js-namespace-rails' 8 | spec.version = JsNamespaceRails::VERSION 9 | spec.authors = ['Jason Hou'] 10 | spec.email = ['hjj1992@gmail.com'] 11 | 12 | spec.summary = %q{js-namespace-rails let you choose which javascript snippet can execute in rails assets pipeline} 13 | spec.description = %q{Namespace and Selectively Execute Javascript} 14 | spec.homepage = 'https://github.com/falm/js-namespace-rails' 15 | 16 | spec.files = Dir['{lib,app}/**/*'] + %w{README.md} 17 | spec.bindir = 'exe' 18 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 19 | spec.require_paths = ['lib'] 20 | 21 | spec.licenses = ["MIT"] 22 | 23 | spec.required_ruby_version = '>= 2.0' 24 | spec.add_development_dependency 'railties', '>= 3.1' 25 | spec.add_development_dependency 'sprockets-rails' 26 | spec.add_development_dependency "bundler", ">= 1.8" 27 | spec.add_development_dependency "rake", "~> 10.0" 28 | spec.add_development_dependency 'rspec-rails' 29 | spec.add_development_dependency "coveralls", '~> 0.7' 30 | spec.add_development_dependency 'capybara' 31 | spec.add_development_dependency 'rack', '~> 1.5' 32 | spec.add_development_dependency 'capybara-webkit' 33 | end 34 | -------------------------------------------------------------------------------- /lib/js-namespace-rails.rb: -------------------------------------------------------------------------------- 1 | require 'js_namespace_rails' 2 | -------------------------------------------------------------------------------- /lib/js_namespace_rails.rb: -------------------------------------------------------------------------------- 1 | #encoding: utf-8 2 | 3 | Gem.find_files('js_namespace_rails/**/*.rb').each { |file| require file } 4 | 5 | module JsNamespaceRails 6 | 7 | end 8 | -------------------------------------------------------------------------------- /lib/js_namespace_rails/action_controller_extension.rb: -------------------------------------------------------------------------------- 1 | 2 | module JsNamespaceRails 3 | module ActionControllerExtension 4 | 5 | def self.included(base) 6 | base.module_eval do 7 | helper_method :js_execute 8 | helper_method :insert_hook_script 9 | helper_method :initialize_script 10 | end 11 | end 12 | 13 | def js(params) 14 | @js_namespace_rails_params ||= {} 15 | @js_namespace_rails_params = @js_namespace_rails_params.merge(params) 16 | end 17 | 18 | def js_execute 19 | view_context.render partial: 'js_namespace_rails/init.js.erb' 20 | end 21 | 22 | def insert_hook_script 23 | view_context.render partial: 'js_namespace_rails/hook.js.erb' 24 | end 25 | 26 | def initialize_script 27 | view_context.render partial: 'js_namespace_rails/initialize_script.html.erb' 28 | end 29 | end 30 | ::ActionController::Base.send :include, ActionControllerExtension 31 | end 32 | -------------------------------------------------------------------------------- /lib/js_namespace_rails/action_view/helpers/asset_tag_helper.rb: -------------------------------------------------------------------------------- 1 | module ActionView::Helpers::AssetTagHelper 2 | 3 | # load twice will raise exception 'stack level too deep' 4 | unless defined?(:javascript_include_tag_without_controller) 5 | alias_method :javascript_include_tag_without_controller, :javascript_include_tag 6 | 7 | def javascript_include_tag(*source) 8 | 9 | if defined?(controller_path) && !@_included 10 | @_included = true 11 | concat javascript_tag(insert_hook_script, defer: 'defer') 12 | end 13 | javascript_include_tag_without_controller(*source) 14 | end 15 | end 16 | 17 | end 18 | -------------------------------------------------------------------------------- /lib/js_namespace_rails/engine.rb: -------------------------------------------------------------------------------- 1 | require 'js_namespace_rails/version' 2 | 3 | module JsNamespaceRails 4 | 5 | class Engine < ::Rails::Engine 6 | 7 | end 8 | 9 | end -------------------------------------------------------------------------------- /lib/js_namespace_rails/version.rb: -------------------------------------------------------------------------------- 1 | module JsNamespaceRails 2 | VERSION = '1.1.1' 3 | end 4 | -------------------------------------------------------------------------------- /spec/dummy/README.rdoc: -------------------------------------------------------------------------------- 1 | == README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | 26 | 27 | Please feel free to use a different markup language if you do not plan to run 28 | rake doc:app. 29 | -------------------------------------------------------------------------------- /spec/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falm/js-namespace-rails/45574ade80c13f6c87c752418f2f4bbf7c38e8e0/spec/dummy/app/assets/images/.keep -------------------------------------------------------------------------------- /spec/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require js-namespace-rails 16 | //= require_tree . 17 | 18 | 19 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/javascripts/users.es6: -------------------------------------------------------------------------------- 1 | JsSpace.on('users', { 2 | init(){ 3 | $('.common-place').text('common_action_works') 4 | }, 5 | index(){ 6 | $('.title').text('user_list'); 7 | var puts = ['user_id', this.params.user_id, 'user_name', this.params.user_name].join(':'); 8 | $('.common-place').append(puts); 9 | }, 10 | _new(){ 11 | $('.h1-title').text('new_user'); 12 | }, 13 | show(){ 14 | $('.common-place').append('show-user'); 15 | $('.common-place').append(this.params.message); 16 | } 17 | }); -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /spec/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | # Prevent CSRF attacks by raising an exception. 3 | # For APIs, you may want to use :null_session instead. 4 | protect_from_forgery with: :exception 5 | end 6 | -------------------------------------------------------------------------------- /spec/dummy/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falm/js-namespace-rails/45574ade80c13f6c87c752418f2f4bbf7c38e8e0/spec/dummy/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /spec/dummy/app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | #encoding: utf-8 2 | class UsersController < ApplicationController 3 | 4 | def index 5 | js user_name: 'Neo' 6 | js user_id: 11 7 | end 8 | 9 | def new 10 | end 11 | 12 | def show 13 | js message: 'May the force be with you' 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /spec/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /spec/dummy/app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falm/js-namespace-rails/45574ade80c13f6c87c752418f2f4bbf7c38e8e0/spec/dummy/app/mailers/.keep -------------------------------------------------------------------------------- /spec/dummy/app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falm/js-namespace-rails/45574ade80c13f6c87c752418f2f4bbf7c38e8e0/spec/dummy/app/models/.keep -------------------------------------------------------------------------------- /spec/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falm/js-namespace-rails/45574ade80c13f6c87c752418f2f4bbf7c38e8e0/spec/dummy/app/models/concerns/.keep -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | <%= stylesheet_link_tag 'application', media: 'all' %> 6 | <%= javascript_include_tag 'application' %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/frontend.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | <%= stylesheet_link_tag 'application', media: 'all' %> 6 | <%= javascript_include_tag 'frontend' %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | <%= initialize_script %> 13 | 14 | 15 | -------------------------------------------------------------------------------- /spec/dummy/app/views/users/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

3 |

4 |

User List

5 | 6 | 7 | 8 | 9 |
10 | 11 | <%= link_to 'Show', user_path(id: 1), remote: true %> 12 | <%= link_to 'New', new_user_path %> 13 |
14 | -------------------------------------------------------------------------------- /spec/dummy/app/views/users/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

3 |

4 |
5 | -------------------------------------------------------------------------------- /spec/dummy/app/views/users/show.js.erb: -------------------------------------------------------------------------------- 1 | <%= js_execute %> 2 | -------------------------------------------------------------------------------- /spec/dummy/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /spec/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /spec/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /spec/dummy/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | 4 | # path to your application root. 5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 6 | 7 | Dir.chdir APP_ROOT do 8 | # This script is a starting point to setup your application. 9 | # Add necessary setup steps to this file: 10 | 11 | puts "== Installing dependencies ==" 12 | system "gem install bundler --conservative" 13 | system "bundle check || bundle install" 14 | 15 | # puts "\n== Copying sample files ==" 16 | # unless File.exist?("config/database.yml") 17 | # system "cp config/database.yml.sample config/database.yml" 18 | # end 19 | 20 | puts "\n== Preparing database ==" 21 | system "bin/rake db:setup" 22 | 23 | puts "\n== Removing old logs and tempfiles ==" 24 | system "rm -f log/*" 25 | system "rm -rf tmp/cache" 26 | 27 | puts "\n== Restarting application server ==" 28 | system "touch tmp/restart.txt" 29 | end 30 | -------------------------------------------------------------------------------- /spec/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /spec/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | # Pick the frameworks you want: 4 | # require "active_record/railtie" 5 | require "action_controller/railtie" 6 | # require "action_mailer/railtie" 7 | require "action_view/railtie" 8 | require "sprockets/railtie" 9 | # require "rails/test_unit/railtie" 10 | 11 | Bundler.require(*Rails.groups) 12 | require "js_namespace_rails" 13 | 14 | module Dummy 15 | class Application < Rails::Application 16 | # Settings in config/environments/* take precedence over those specified here. 17 | # Application configuration should go into files in config/initializers 18 | # -- all .rb files in that directory are automatically loaded. 19 | 20 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 21 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 22 | # config.time_zone = 'Central Time (US & Canada)' 23 | 24 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 25 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 26 | # config.i18n.default_locale = :de 27 | 28 | # Do not swallow errors in after_commit/after_rollback callbacks. 29 | # config.active_record.raise_in_transactional_callbacks = true 30 | end 31 | end 32 | 33 | -------------------------------------------------------------------------------- /spec/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) 5 | $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) 6 | -------------------------------------------------------------------------------- /spec/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /spec/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send. 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger. 20 | config.active_support.deprecation = :log 21 | 22 | # Raise an error on page load if there are pending migrations. 23 | config.active_record.migration_error = :page_load 24 | 25 | # Debug mode disables concatenation and preprocessing of assets. 26 | # This option may cause significant delays in view rendering with a large 27 | # number of complex assets. 28 | config.assets.debug = true 29 | 30 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 31 | # yet still be able to expire them through the digest params. 32 | config.assets.digest = true 33 | 34 | # Adds additional error checking when serving assets at runtime. 35 | # Checks for improperly declared sprockets dependencies. 36 | # Raises helpful error messages. 37 | config.assets.raise_runtime_errors = true 38 | 39 | # Raises error for missing translations 40 | # config.action_view.raise_on_missing_translations = true 41 | end 42 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like 20 | # NGINX, varnish or squid. 21 | # config.action_dispatch.rack_cache = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 26 | 27 | # Compress JavaScripts and CSS. 28 | config.assets.js_compressor = :uglifier 29 | # config.assets.css_compressor = :sass 30 | 31 | # Do not fallback to assets pipeline if a precompiled asset is missed. 32 | config.assets.compile = false 33 | 34 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 35 | # yet still be able to expire them through the digest params. 36 | config.assets.digest = true 37 | 38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 39 | 40 | # Specifies the header that your server uses for sending files. 41 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 42 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 43 | 44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 45 | # config.force_ssl = true 46 | 47 | # Use the lowest log level to ensure availability of diagnostic information 48 | # when problems arise. 49 | config.log_level = :debug 50 | 51 | # Prepend all log lines with the following tags. 52 | # config.log_tags = [ :subdomain, :uuid ] 53 | 54 | # Use a different logger for distributed setups. 55 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 56 | 57 | # Use a different cache store in production. 58 | # config.cache_store = :mem_cache_store 59 | 60 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 61 | # config.action_controller.asset_host = 'http://assets.example.com' 62 | 63 | # Ignore bad email addresses and do not raise email delivery errors. 64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 65 | # config.action_mailer.raise_delivery_errors = false 66 | 67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 68 | # the I18n.default_locale when a translation cannot be found). 69 | config.i18n.fallbacks = true 70 | 71 | # Send deprecation notices to registered listeners. 72 | config.active_support.deprecation = :notify 73 | 74 | # Use default logging formatter so that PID and timestamp are not suppressed. 75 | config.log_formatter = ::Logger::Formatter.new 76 | 77 | # Do not dump schema after migrations. 78 | config.active_record.dump_schema_after_migration = false 79 | end 80 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static file server for tests with Cache-Control for performance. 16 | config.serve_static_files = true 17 | config.static_cache_control = 'public, max-age=3600' 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Tell Action Mailer not to deliver emails to the real world. 30 | # The :test delivery method accumulates sent emails in the 31 | # ActionMailer::Base.deliveries array. 32 | # config.action_mailer.delivery_method = :test 33 | 34 | # Randomize the order test cases are executed. 35 | config.active_support.test_order = :random 36 | 37 | # Print deprecation notices to the stderr. 38 | config.active_support.deprecation = :stderr 39 | 40 | # Raises error for missing translations 41 | # config.action_view.raise_on_missing_translations = true 42 | end 43 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.action_dispatch.cookies_serializer = :json 4 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_dummy_session' 4 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /spec/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /spec/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | 3 | mount JsNamespaceRails::Engine => "/js_namespace_rails" 4 | 5 | resources :users 6 | 7 | resources :articles 8 | 9 | end 10 | -------------------------------------------------------------------------------- /spec/dummy/config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 5868f45ddcdaa61f053cfb94bb213aed30ef7802330740f765e76349ab916a89ff2dc2b98572b89b07f566b02e0d1bcad61facd4737dc8ea79c34b142c4ea9ac 15 | 16 | test: 17 | secret_key_base: 62a101d5e15ffd1f82c934513bf7c3f72b821bfb94def69ed7f68cc4ab536c2dcb8cb647ad3b7314d0094f7c89a7a06f8f5ddaae83d93ae0d8573503fb2ede78 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /spec/dummy/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falm/js-namespace-rails/45574ade80c13f6c87c752418f2f4bbf7c38e8e0/spec/dummy/lib/assets/.keep -------------------------------------------------------------------------------- /spec/dummy/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falm/js-namespace-rails/45574ade80c13f6c87c752418f2f4bbf7c38e8e0/spec/dummy/log/.keep -------------------------------------------------------------------------------- /spec/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /spec/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /spec/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /spec/dummy/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falm/js-namespace-rails/45574ade80c13f6c87c752418f2f4bbf7c38e8e0/spec/dummy/public/favicon.ico -------------------------------------------------------------------------------- /spec/js_namepsace_rails_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe JsNamespaceRails, js: true do 4 | 5 | include Capybara::DSL 6 | 7 | context 'Index' do 8 | before(:each) do 9 | visit '/users' 10 | end 11 | 12 | it 'visit users page will have contain current controller name and action name' do 13 | 14 | controller_name = find('body')['data-controller'] 15 | 16 | action_name = find('body')['data-action'] 17 | 18 | expect(controller_name).to eq('users') 19 | 20 | expect(action_name).to eq('index') 21 | 22 | end 23 | 24 | it 'action evaluate will works' do 25 | 26 | expect(page).to have_css('h1.title') 27 | 28 | expect(page).to have_content('user_list') 29 | 30 | end 31 | 32 | it 'common behavior of controller will be works' do 33 | 34 | expect(page).to have_content('common_action_works') 35 | 36 | end 37 | 38 | it 'should passing params to users js action' do 39 | # puts page.driver.console_messages 40 | 41 | expect(page).to have_content('user_name:Neo') 42 | 43 | expect(page).to have_content('user_id:11') 44 | end 45 | 46 | it 'should trigger js execute method' do 47 | # save_and_open_page 48 | expect(page).to have_content('Show') 49 | click_link 'Show' 50 | expect(page).to have_content('show-user') 51 | 52 | end 53 | 54 | it 'should trigger js execute with params' do 55 | expect(page).to have_content('Show') 56 | click_link 'Show' 57 | expect(page).to have_content('May the force be with you') 58 | end 59 | 60 | end 61 | 62 | it 'should new action works' do 63 | visit '/users/new' 64 | # puts page.driver.console_messages 65 | save_and_open_page 66 | expect(page).to have_content('new_user') 67 | 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | #encoding: utf-8 2 | ENV["RAILS_ENV"] ||= 'test' 3 | 4 | require 'coveralls' 5 | Coveralls.wear! 6 | 7 | require File.expand_path("../dummy/config/environment", __FILE__) 8 | 9 | require 'rails/all' 10 | require 'rspec/rails' 11 | require 'jquery-rails' 12 | require 'js-namespace-rails' 13 | require 'capybara/rspec' 14 | require 'capybara-webkit' 15 | 16 | require 'bundler/setup' 17 | Bundler.setup 18 | 19 | # This file was generated by the `rspec --init` command. Conventionally, all 20 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 21 | # The generated `.rspec` file contains `--require spec_helper` which will cause 22 | # this file to always be loaded, without a need to explicitly require it in any 23 | # files. 24 | # 25 | # Given that it is always loaded, you are encouraged to keep this file as 26 | # light-weight as possible. Requiring heavyweight dependencies from this file 27 | # will add to the boot time of your test suite on EVERY test run, even for an 28 | # individual file that may not need all of that loaded. Instead, consider making 29 | # a separate helper file that requires the additional dependencies and performs 30 | # the additional setup, and require it from the spec files that actually need 31 | # it. 32 | # 33 | # The `.rspec` file also contains a few flags that are not defaults but that 34 | # users commonly want. 35 | # 36 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 37 | 38 | # Capybara.javascript_driver = :selenium 39 | 40 | # Capybara.register_driver :chrome do |app| 41 | 42 | # Capybara::Selenium::Driver.new(app, browser: :chrome, inspector: true) 43 | 44 | # end 45 | 46 | # setting up Capybara webkit 47 | Capybara.javascript_driver = :webkit 48 | 49 | Capybara::Webkit.configure do |config| 50 | # config.debug = true 51 | end 52 | 53 | Rails.backtrace_cleaner.remove_silencers! 54 | 55 | RSpec.configure do |config| 56 | 57 | # assertions if you prefer. 58 | config.expect_with :rspec do |expectations| 59 | # This option will default to `true` in RSpec 4. It makes the `description` 60 | # and `failure_message` of custom matchers include text for helper methods 61 | # defined using `chain`, e.g.: 62 | # be_bigger_than(2).and_smaller_than(4).description 63 | # # => "be bigger than 2 and smaller than 4" 64 | # ...rather than: 65 | # # => "be bigger than 2" 66 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 67 | end 68 | 69 | # rspec-mocks config goes here. You can use an alternate test double 70 | # library (such as bogus or mocha) by changing the `mock_with` option here. 71 | config.mock_with :rspec do |mocks| 72 | # Prevents you from mocking or stubbing a method that does not exist on 73 | # a real object. This is generally recommended, and will default to 74 | # `true` in RSpec 4. 75 | mocks.verify_partial_doubles = true 76 | end 77 | 78 | # The settings below are suggested to provide a good initial experience 79 | # with RSpec, but feel free to customize to your heart's content. 80 | =begin 81 | # These two settings work together to allow you to limit a spec run 82 | # to individual examples or groups you care about by tagging them with 83 | # `:focus` metadata. When nothing is tagged with `:focus`, all examples 84 | # get run. 85 | config.filter_run :focus 86 | config.run_all_when_everything_filtered = true 87 | 88 | # Allows RSpec to persist some state between runs in order to support 89 | # the `--only-failures` and `--next-failure` CLI options. We recommend 90 | # you configure your source control system to ignore this file. 91 | config.example_status_persistence_file_path = "spec/examples.txt" 92 | 93 | # Limits the available syntax to the non-monkey patched syntax that is 94 | # recommended. For more details, see: 95 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 96 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 97 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 98 | config.disable_monkey_patching! 99 | 100 | # This setting enables warnings. It's recommended, but in some cases may 101 | # be too noisy due to issues in dependencies. 102 | config.warnings = true 103 | 104 | # Many RSpec users commonly either run the entire suite or an individual 105 | # file, and it's useful to allow more verbose output when running an 106 | # individual spec file. 107 | if config.files_to_run.one? 108 | # Use the documentation formatter for detailed output, 109 | # unless a formatter has already been configured 110 | # (e.g. via a command-line flag). 111 | config.default_formatter = 'doc' 112 | end 113 | 114 | # Print the 10 slowest examples and example groups at the 115 | # end of the spec run, to help surface which specs are running 116 | # particularly slow. 117 | config.profile_examples = 10 118 | 119 | # Run specs in random order to surface order dependencies. If you find an 120 | # order dependency and want to debug it, you can fix the order by providing 121 | # the seed, which is printed after each run. 122 | # --seed 1234 123 | config.order = :random 124 | 125 | # Seed global randomization in this process using the `--seed` CLI option. 126 | # Setting this allows you to use `--seed` to deterministically reproduce 127 | # test failures related to randomization by passing the same `--seed` value 128 | # as the one that triggered the failure. 129 | Kernel.srand config.seed 130 | =end 131 | end 132 | --------------------------------------------------------------------------------