Skip to content

Instantly share code, notes, and snippets.

@livecodelife
Last active November 25, 2021 22:40

Revisions

  1. livecodelife revised this gist Aug 8, 2017. No changes.
  2. livecodelife revised this gist Aug 8, 2017. No changes.
  3. livecodelife revised this gist Mar 2, 2017. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions rails_engine_setup.md
    Original file line number Diff line number Diff line change
    @@ -8,14 +8,16 @@
    - `gem 'capybara'` - act as a user navigating your site in tests ([docs](https://github.com/jnicklas/capybara))
    - `gem 'factory_girl_rails'` - easily generate database objects without repetitive code in tests ([docs](https://github.com/thoughtbot/factory_girl_rails))
    - `gem 'database_cleaner'` - clean your database between tests ([docs](https://github.com/DatabaseCleaner/database_cleaner))
    3. Bundle and install (`bundle exec` or `rails g`) where required, create additional required files
    3. In project_name.gemspec
    - Change `s.homepage`, `s.summary`, and `s.description` to the correct info
    4. Bundle and install (`bundle exec` or `rails g`) where required, create additional required files
    - `bundle`
    - `rails g rspec:install`
    - `mkdir spec/support`
    - `touch spec/support/factory_girl.rb`
    - `touch spec/support/factories.rb`
    - `touch spec/support/database_cleaner.rb`
    4. Add config data
    5. Add config data
    - In `spec/rails_helper.rb`
    `require 'capybara/rails'`

    @@ -66,7 +68,7 @@
    end
    ```
    5. In lib/project_name/engine.rb:
    6. In lib/project_name/engine.rb:
    ```
    config.generators do |g|
    g.test_framework :rspec
  4. livecodelife revised this gist Feb 28, 2017. 1 changed file with 14 additions and 6 deletions.
    20 changes: 14 additions & 6 deletions rails_engine_setup.md
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,11 @@
    - `--dummy-path=spec/dummy` sets up your dummy app in a spec directory
    - `--skip-turbolinks` & `--skip-spring` creates a project that does not use turbolinks or spring
    - `--mountable` creates a "mountable" and namespace-isolated engine.
    2. In project_name.gemspec file:
    - `s.add_development_dependency 'rspec-rails'` - user rspec in place of minitest ([docs](https://github.com/rspec/rspec-rails))
    - `s.add_development_dependency 'capybara'` - act as a user navigating your site in tests ([docs](https://github.com/jnicklas/capybara))
    - `s.add_development_dependency 'factory_girl_rails'` - easily generate database objects without repetitive code in tests ([docs](https://github.com/thoughtbot/factory_girl_rails))
    - `s.add_development_dependency 'database_cleaner'` - clean your database between tests ([docs](https://github.com/DatabaseCleaner/database_cleaner))
    2. In Gemfile:
    - `gem 'rspec-rails'` - user rspec in place of minitest ([docs](https://github.com/rspec/rspec-rails))
    - `gem 'capybara'` - act as a user navigating your site in tests ([docs](https://github.com/jnicklas/capybara))
    - `gem 'factory_girl_rails'` - easily generate database objects without repetitive code in tests ([docs](https://github.com/thoughtbot/factory_girl_rails))
    - `gem 'database_cleaner'` - clean your database between tests ([docs](https://github.com/DatabaseCleaner/database_cleaner))
    3. Bundle and install (`bundle exec` or `rails g`) where required, create additional required files
    - `bundle`
    - `rails g rspec:install`
    @@ -65,4 +65,12 @@
    end
    ```
    5. In lib/project_name/engine.rb:
    ```
    config.generators do |g|
    g.test_framework :rspec
    g.fixture_replacement :factory_girl, :dir => 'spec/support/factories'
    end

    ```
  5. livecodelife revised this gist Feb 28, 2017. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion rails_engine_setup.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    This sets up an easily testable mountable rails engine project</br>
    1. `rails plugin new <project_name> -T -d postgresql --dummy-path=spec/dummy --skip-turbolinks --skip-spring --mountable`
    - `-T` skips the creation of the test directory and the use of `Test::Unit`
    - `--dummy-path=spec/dummy` sets up your dummy app in a spec directory
  6. livecodelife revised this gist Feb 28, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rails_engine_setup.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    This sets up an easily testable mountable rails engine project
    This sets up an easily testable mountable rails engine project</br>
    1. `rails plugin new <project_name> -T -d postgresql --dummy-path=spec/dummy --skip-turbolinks --skip-spring --mountable`
    - `-T` skips the creation of the test directory and the use of `Test::Unit`
    - `--dummy-path=spec/dummy` sets up your dummy app in a spec directory
  7. livecodelife revised this gist Feb 28, 2017. No changes.
  8. livecodelife revised this gist Feb 28, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions rails_engine_setup.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    This sets up an easily testable mountable rails engine project
    1. `rails plugin new <project_name> -T -d postgresql --dummy-path=spec/dummy --skip-turbolinks --skip-spring --mountable`
    - `-T` skips the creation of the test directory and the use of `Test::Unit`
    - `--dummy-path=spec/dummy` sets up your dummy app in a spec directory
  9. livecodelife revised this gist Feb 28, 2017. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion rails_engine_setup.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    1. `rails plugin new <project_name> -T -d postgresql --dummy-path=spec/dummy --skip-turbolinks --skip-spring --mountable`
    - `-T` skips the creation of the test directory and the use of `Test::Unit`
    - `--dummy-path=spec/dummy` sets up your dummy app in a spec directory
    - `--dummy-path=spec/dummy` sets up your dummy app in a spec directory]
    - `--skip-turbolinks` & `--skip-spring` creates a project that does not use turbolinks or spring
    - `--mountable` creates a "mountable" and namespace-isolated engine.
    2. In project_name.gemspec file:
  10. livecodelife created this gist Feb 28, 2017.
    69 changes: 69 additions & 0 deletions rails_engine_setup.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    1. `rails plugin new <project_name> -T -d postgresql --dummy-path=spec/dummy --skip-turbolinks --skip-spring --mountable`
    - `-T` skips the creation of the test directory and the use of `Test::Unit`
    - `--dummy-path=spec/dummy` sets up your dummy app in a spec directory
    - `--dummy-path=spec/dummy` sets up your dummy app in a spec directory]
    - `--skip-turbolinks` & `--skip-spring` creates a project that does not use turbolinks or spring
    - `--mountable` creates a "mountable" and namespace-isolated engine.
    2. In project_name.gemspec file:
    - `s.add_development_dependency 'rspec-rails'` - user rspec in place of minitest ([docs](https://github.com/rspec/rspec-rails))
    - `s.add_development_dependency 'capybara'` - act as a user navigating your site in tests ([docs](https://github.com/jnicklas/capybara))
    - `s.add_development_dependency 'factory_girl_rails'` - easily generate database objects without repetitive code in tests ([docs](https://github.com/thoughtbot/factory_girl_rails))
    - `s.add_development_dependency 'database_cleaner'` - clean your database between tests ([docs](https://github.com/DatabaseCleaner/database_cleaner))
    3. Bundle and install (`bundle exec` or `rails g`) where required, create additional required files
    - `bundle`
    - `rails g rspec:install`
    - `mkdir spec/support`
    - `touch spec/support/factory_girl.rb`
    - `touch spec/support/factories.rb`
    - `touch spec/support/database_cleaner.rb`
    4. Add config data
    - In `spec/rails_helper.rb`
    `require 'capybara/rails'`

    - Uncomment `Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }`
    - Change `config.use_transactional_fixtures = true` to `... = false`

    - In `spec/support/factory_girl.rb`
    ```
    RSpec.configure do |config|
    config.include FactoryGirl::Syntax::Methods
    end
    ```
    - In `spec/support/factories.rb`
    ```
    FactoryGirl.define do
    <factories for each model go here>
    end
    ```
    - In `spec/support/database_cleaner.rb`
    ```
    RSpec.configure do |config|
    config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
    end
    config.before(:each) do
    DatabaseCleaner.strategy = :transaction
    end
    config.before(:each, :js => true) do
    DatabaseCleaner.strategy = :truncation
    end
    config.before(:each) do
    DatabaseCleaner.start
    end
    config.after(:each) do
    DatabaseCleaner.clean
    end
    # Optional for formatting output of test suite runs (see comments)
    config.formatter = :documentation
    end
    ```