Bladeren bron

Separate feature and non feature spec runs on travis

Add database_cleaner gem
Set up coveralls parralel builds in travisci
Require capybara_helper in rails_helper to make clear it affects all tests
Dominik Sander 9 jaren geleden
bovenliggende
commit
a6a06c1cd1

+ 11 - 7
.travis.yml

@@ -7,6 +7,8 @@ services:
 env:
   global:
     - APP_SECRET_TOKEN=b2724973fd81c2f4ac0f92ac48eb3f0152c4a11824c122bcf783419a4c51d8b9bba81c8ba6a66c7de599677c7f486242cf819775c433908e77c739c5c8ae118d
+    - RSPEC_TASK=spec:nofeatures
+    - COVERALLS_PARALLEL=true
     - secure: fzmSI7PQz6CJiIJNAtLAuy3TMmYCrK4bUil3uufh8JkHfpSGWOZt2i6fZ8yZ7pzwG5Aw7eZDgdFsNcEPJlgUDJhlwjg+QxCJslhotTQ9qI3Ieo85peWlU9dZFTOZcrCu0net/hY2FE4ZpTRb5r8A/DRv9ukA8P8tShhePCjckgg=
     - secure: YjW07LpRSiC9xB6PhLQ4LVv2VphvF3IacV43PLfvzdagjy14yAwKXTUlSadgRaMbndB2dlCTe3YcY11a/xtX/2HDrF14NHPXQdL7e2dJUS3CDLSKZK26x1SOiaaDIrl1jO1xr5kOUd+564MAcNUzDTJQR4CrWl/5t6EwW4iYQVc=
     - secure: RJiSTB9Anax6uL6mgYY1m42w71ohlsfIlVCk7ho6W19ZfSzQOfom0mBdeNwfgmXsMMnvnqatfxSg8k3C//pRtI/tjzAovHd7t1YIN1IkDNf9uSpzrIeXXc4fSHaVxnl512oI/eBQy9MSBjVZjrg5XEzLKKEGsZCai+ZKB4PS+nM=
@@ -15,15 +17,21 @@ env:
     - DATABASE_ADAPTER=postgresql DATABASE_USERNAME=postgres
     - DOCKER_IMAGE=cantino/huginn-single-process DOCKERFILE=docker/single-process/Dockerfile
     - DOCKER_IMAGE=cantino/huginn DOCKERFILE=docker/multi-process/Dockerfile
+    - RSPEC_TASK=spec:features
 matrix:
   exclude:
     - env: DOCKER_IMAGE=cantino/huginn-single-process DOCKERFILE=docker/single-process/Dockerfile
     - env: DOCKER_IMAGE=cantino/huginn DOCKERFILE=docker/multi-process/Dockerfile
+    - env: RSPEC_TASK=spec:features
   include:
     - rvm: 2.3.0
       env: DATABASE_ADAPTER=mysql2 DOCKER_IMAGE=cantino/huginn-single-process DOCKERFILE=docker/single-process/Dockerfile
     - rvm: 2.3.0
       env: DATABASE_ADAPTER=mysql2 DOCKER_IMAGE=cantino/huginn DOCKERFILE=docker/multi-process/Dockerfile
+    - rvm: 2.3.0
+      env: RSPEC_TASK=spec:features DATABASE_ADAPTER=mysql2
+    - rvm: 2.3.0
+      env: RSPEC_TASK=spec:features DATABASE_ADAPTER=postgresql DATABASE_USERNAME=postgres
 rvm:
 - 2.1
 - 2.2
@@ -34,7 +42,8 @@ before_install:
   - sudo apt-get -qq update
   - sudo apt-get install -y mysql-server
 script:
-  - if [ -z "${DOCKER_IMAGE}" ]; then bundle exec rake db:create db:migrate && bundle exec rake; else ./build_docker_image.sh; fi
+  - if [ -z "${DOCKER_IMAGE}" ]; then bundle exec rake db:create db:migrate; else true; fi
+  - if [ -z "${DOCKER_IMAGE}" ]; then bundle exec rake $RSPEC_TASK; else ./build_docker_image.sh; fi
 notifications:
   irc:
     channels:
@@ -43,9 +52,4 @@ notifications:
     - "<%{author}> %{branch} - %{commit} (%{commit_message}): %{message}"
     - 'Change view : %{compare_url}'
     - 'Build details : %{build_url}'
-  webhooks:
-    urls:
-      - https://webhooks.gitter.im/e/5f92cc0393c6f1defe0d
-    on_success: change  # options: [always|never|change] default: always
-    on_failure: always  # options: [always|never|change] default: always
-    on_start: never     # options: [always|never|change] default: never
+  webhooks: https://coveralls.io/webhook?repo_token=COVERALLS_REPO_TOKEN

+ 1 - 0
Gemfile

@@ -155,6 +155,7 @@ group :development do
     gem 'shoulda-matchers'
     gem 'vcr'
     gem 'webmock', '~> 1.17.4', require: false
+    gem 'database_cleaner', '~> 1.5.3'
   end
 end
 

+ 2 - 0
Gemfile.lock

@@ -166,6 +166,7 @@ GEM
     crack (0.4.2)
       safe_yaml (~> 1.0.0)
     daemons (1.1.9)
+    database_cleaner (1.5.3)
     debug_inspector (0.0.2)
     delayed_job (4.1.1)
       activesupport (>= 3.0, < 5.0)
@@ -599,6 +600,7 @@ DEPENDENCIES
   coffee-rails (~> 4.1.1)
   coveralls
   daemons (~> 1.1.9)
+  database_cleaner (~> 1.5.3)
   delayed_job (~> 4.1.0)
   delayed_job_active_record!
   delorean

+ 9 - 0
lib/tasks/rspec.rake

@@ -0,0 +1,9 @@
+if defined? RSpec
+  namespace :spec do
+    desc 'Run all specs in spec directory (exluding feature specs)'
+    RSpec::Core::RakeTask.new(:nofeatures) do |task|
+      ENV['RSPEC_TASK'] = 'spec:nofeatures'
+      task.exclude_pattern = "spec/features/**/*_spec.rb"
+    end
+  end
+end

+ 10 - 2
spec/capybara_helper.rb

@@ -15,11 +15,19 @@ Capybara.default_max_wait_time = CAPYBARA_TIMEOUT
 RSpec.configure do |config|
   config.include Warden::Test::Helpers
   config.include AlertConfirmer, type: :feature
-  config.before :suite do
+
+  config.before(:suite) do
     Warden.test_mode!
+    DatabaseCleaner.clean_with(:truncation)
+  end
+
+  config.before(:each) do |example|
+    DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
+    DatabaseCleaner.start
   end
 
-  config.after :each do
+  config.after(:each) do
+    DatabaseCleaner.clean
     Warden.test_reset!
   end
 end

+ 1 - 1
spec/features/admin_users_spec.rb

@@ -1,4 +1,4 @@
-require 'capybara_helper'
+require 'rails_helper'
 
 describe Admin::UsersController do
   it "requires to be signed in as an admin" do

+ 1 - 1
spec/features/create_an_agent_spec.rb

@@ -1,4 +1,4 @@
-require 'capybara_helper'
+require 'rails_helper'
 
 describe "Creating a new agent", js: true do
   before(:each) do

+ 1 - 1
spec/features/edit_an_agent_spec.rb

@@ -1,4 +1,4 @@
-require 'capybara_helper'
+require 'rails_helper'
 
 describe "Editing an agent", js: true do
   it "creates an alert if a agent with invalid json is submitted" do

+ 5 - 1
spec/rails_helper.rb

@@ -38,7 +38,7 @@ RSpec.configure do |config|
   # If you're not using ActiveRecord, or you'd prefer not to run each of your
   # examples within a transaction, remove the following line or assign false
   # instead of true.
-  config.use_transactional_fixtures = true
+  config.use_transactional_fixtures = ENV['RSPEC_TASK'] == 'spec:nofeatures'
 
   # rspec-rails 3 will no longer automatically infer an example group's spec type
   # from the file location. You can explicitly opt-in to this feature using this
@@ -70,3 +70,7 @@ RSpec.configure do |config|
   config.include SpecHelpers
   config.include Delorean
 end
+
+if ENV['RSPEC_TASK'] != 'spec:nofeatures'
+  require 'capybara_helper'
+end