Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null database strategy to disable @javascript handling #522

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on how to contribute to Cucumber.

### New Features

*
* Added `:none` option for `javascript_strategy` which indicates no special handling of `@javascript` tagged tests ([#522](https://github.com/cucumber/cucumber-rails/pull/522) [akostadinov])

### Changed

Expand Down
34 changes: 33 additions & 1 deletion features/choose_javascript_database_strategy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ Feature: Choose javascript database strategy
Right now, the default behavior is to use truncation, but you can override this by telling
cucumber-rails which strategy to use for javascript scenarios.

The deletion strategy can be quicker for situations where truncation causes locks which
The `:deletion` strategy can be quicker for situations where truncation causes locks which
has been reported by some Oracle users.

The `:none` strategy can be used when user doesn't want special handling of scenario
database clean-up regardless of tags set for said scenario.

Background:
Given I have created a new Rails app and installed cucumber-rails
And I have a "Widget" ActiveRecord model object
Expand Down Expand Up @@ -101,6 +104,35 @@ Feature: Choose javascript database strategy
5 steps (5 passed)
"""

Scenario: Set the strategy to none and run a javascript scenario.
When I append to "features/env.rb" with:
"""
DatabaseCleaner.strategy = :transaction
Cucumber::Rails::Database.javascript_strategy = :none
"""
And I write to "features/widgets.feature" with:
"""
Feature:
Background:
When I create 2 widgets

@javascript
Scenario:
When I create 3 widgets
Then I should have 5 widgets
And the DatabaseCleaner strategy should be transaction

Scenario:
Then I should have 2 widgets
And the DatabaseCleaner strategy should be transaction
"""
And I run the cukes
Then the feature run should pass with:
"""
2 scenarios (2 passed)
7 steps (7 passed)
"""

Scenario: Set the strategy to truncation with an except option and run a javascript scenario.
When I append to "features/env.rb" with:
"""
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require 'cucumber/rails/capybara'
require 'cucumber/rails/database/strategy'
require 'cucumber/rails/database/deletion_strategy'
require 'cucumber/rails/database/null_strategy'
require 'cucumber/rails/database/shared_connection_strategy'
require 'cucumber/rails/database/truncation_strategy'
require 'cucumber/rails/database'
Expand Down
3 changes: 2 additions & 1 deletion lib/cucumber/rails/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def map
truncation: TruncationStrategy,
shared_connection: SharedConnectionStrategy,
transaction: SharedConnectionStrategy,
deletion: DeletionStrategy
deletion: DeletionStrategy,
none: NullStrategy
}
end

Expand Down
15 changes: 15 additions & 0 deletions lib/cucumber/rails/database/null_strategy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Cucumber
module Rails
module Database
class NullStrategy
def before_js; end

def before_non_js; end

def after; end
end
end
end
end
1 change: 1 addition & 0 deletions spec/cucumber/rails/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'database_cleaner'
require 'cucumber/rails/database/strategy'
require 'cucumber/rails/database/deletion_strategy'
require 'cucumber/rails/database/null_strategy'
require 'cucumber/rails/database/shared_connection_strategy'
require 'cucumber/rails/database/truncation_strategy'
require 'cucumber/rails/database'
Expand Down