Skip to content

Commit

Permalink
Merge pull request #5167 from ChrisBr/bootstrap/ci
Browse files Browse the repository at this point in the history
Implement feature test suite for bootstrap theming
  • Loading branch information
bgeuken committed Jun 21, 2018
2 parents d1775cc + 35608d4 commit a36785b
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 21 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?
User.current && (User.current.is_admin? || User.current.is_staff?)
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/config/feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ production:
kiwi_image_editor: false
cloud_upload: false
cloud_upload_azure: false
bootstrap: false

development:
features:
<<: *default
kiwi_image_editor: true
cloud_upload: true
cloud_upload_azure: true
bootstrap: false

test:
features:
<<: *default
kiwi_image_editor: true
cloud_upload: true
cloud_upload_azure: true
bootstrap: false
1 change: 1 addition & 0 deletions src/api/script/api_test_in_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ MYSQL_DATADIR=$MYSQL_BASEDIR/data
MEMCACHED_PID_FILE=$TEMP_DIR/memcached.pid
MYSQL_SOCKET_DIR=`mktemp -d`
MYSQL_SOCKET=$MYSQL_SOCKET_DIR/mysql.socket
RETRY=1

MYSQLD_USER=`whoami`
if [[ $EUID == 0 ]];then
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.
22 changes: 3 additions & 19 deletions src/api/spec/browser_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,12 @@

# 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
Dir['./spec/support/shared_examples/features/*.rb'].each { |example| require example }

require 'rspec/retry'
RSpec.configure do |config|
# show retry status in spec process
config.verbose_retry = true
# show exception that triggers a retry if verbose_retry is set to true
config.display_try_failure_messages = true

# run retry only on features
config.around :each, :js do |ex|
ex.run_with_retry retry: 3
end

# callback to be run between retries
config.retry_callback = proc do |ex|
# run some additional clean up task - can be filtered by example metadata
if ex.metadata[:js]
Capybara.reset!
end
end
if ENV['RETRY'].present?
require 'support/features/features_rspec_retry'
end
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
20 changes: 20 additions & 0 deletions src/api/spec/support/features/features_rspec_retry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rspec/retry'
RSpec.configure do |config|
# show retry status in spec process
config.verbose_retry = true
# show exception that triggers a retry if verbose_retry is set to true
config.display_try_failure_messages = true

# run retry only on features
config.around :each, :js do |ex|
ex.run_with_retry retry: 3
end

# callback to be run between retries
config.retry_callback = proc do |ex|
# run some additional clean up task - can be filtered by example metadata
if ex.metadata[:js]
Capybara.reset!
end
end
end

0 comments on commit a36785b

Please sign in to comment.