Skip to content

Commit

Permalink
[ci] Implement feature test suite for bootstrap
Browse files Browse the repository at this point in the history
During the period of migrating our views to bootstrap, we need to run the feature tests twice.
One time with bootstrap disabled and one time enabled.
This can be triggered by setting the BOOTSTRAP environment variable and
excluding the spec/bootstrap/ directory from rspec (see .circleci/config.yml).
If a test does not run with reasonable effort with bootstrap enabled,
the test can be skipped by adding skip_if_bootstrap to the first line of the spec
and we can implementing a new test in spec/bootstrap/ directory.
  • Loading branch information
ChrisBr committed Jun 21, 2018
1 parent f15425d commit 35608d4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
25 changes: 24 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- run: mkdir /home/frontend/rspec
- run:
name: Run rspec
command: cd src/api; bundle exec rspec --format progress --format RspecJunitFormatter -o /home/frontend/rspec/rspec.xml
command: cd src/api; bundle exec rspec --format progress --format RspecJunitFormatter -o /home/frontend/rspec/rspec.xml --exclude-pattern spec/bootstrap/**/*_spec.rb
- run:
name: Format code coverage for code climate
command: ./cc-test-reporter format-coverage --input-type simplecov --output /tmp/coverage/codeclimate.rspec.json src/api/coverage/.resultset.json
Expand All @@ -94,6 +94,26 @@ jobs:
destination: rspec
- store_test_results:
path: /home/frontend/rspec
rspec-bootstrap:
<<: *frontend_base
steps:
- checkout
- run: *download_test_reporter
- restore_cache: *restore_bundle_cache
- run: *install_dependencies
- save_cache: *save_bundle_cache
- run: *wait_for_database
- run:
name: Setup application
command: cd src/api; bundle exec rake dev:bootstrap RAILS_ENV=test
- run:
name: Run rspec with bootstrap enabled
environment:
BOOTSTRAP: 1
command: cd src/api; bundle exec rspec --format progress --pattern spec/features/**/*_spec.rb --pattern spec/bootstrap/**/*_spec.rb
- store_artifacts:
path: ./src/api/log
destination: rspec
minitest:
<<: *minitest
steps:
Expand Down Expand Up @@ -175,6 +195,9 @@ workflows:
- rspec:
requires:
- lint
- rspec-bootstrap:
requires:
- lint
- minitest:
requires:
- lint
Expand Down
9 changes: 8 additions & 1 deletion src/api/app/controllers/webui/webui_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,14 @@ def render_dialog(dialog_init = nil)
end

def switch_to_webui2?
Feature.active?(:bootstrap)
if Rails.env.test?
# In test environment we want to enable the
# bootstrap theme independent from the user
# The feature switch depends on the user (e.g. Admin or Staff)
ENV['BOOTSTRAP'].present
else
Feature.active?(:bootstrap)
end
end

def choose_layout
Expand Down
3 changes: 3 additions & 0 deletions src/api/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ file path of the new one to every test covered.
When you work on the test suite and you notice a method or part of a feature that
is not tested please add a test for it.

### Bootstrap theming
As we are in the progress of migrating our views to a new bootstrap based theming, we currently run our feature tests twice (we do not have view tests). In CircleCI we run the feature tests one time with bootstrap enabled and one time disabled (regardless of the logged in user). Sometimes it can happen that a feature test fails with the bootstrap enabled. The desired solution should be to update the feature test that it works with and without bootstrap. If this is not easily possible, you have the possibility to skip this test for bootstrap by adding ```skip_if_bootstrap``` to the first line of the spec. After that, you should copy over the test to the ```spec/bootstrap/features``` directory and adapt it as necessary.

## Better Specs
As a set of "rules" to follow in our specs we use [BetterSpecs.org](http://betterspecs.org/).
Please read those guidelines before you start coding new specs.
Empty file.
1 change: 1 addition & 0 deletions src/api/spec/browser_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# helper methods for authentication in features tests
require 'support/features/features_authentication'
require 'support/features/features_bootstrap'

# Shared examples. Per recommendation of RSpec,
# https://www.relishapp.com/rspec/rspec-core/v/2-12/docs/example-groups/shared-examples
Expand Down
10 changes: 10 additions & 0 deletions src/api/spec/support/features/features_bootstrap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module FeaturesBootstrap
def skip_if_bootstrap
msg = 'The feature tests are executed with BOOTSTRAP enabled, therefore we skip this test.'
skip(msg) if ENV['BOOTSTRAP'].present?
end
end

RSpec.configure do |c|
c.include FeaturesBootstrap, type: :feature
end

0 comments on commit 35608d4

Please sign in to comment.