From ba288c4aa435aa18820a3f488858ad13482ea2fe Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Sun, 27 Mar 2016 11:54:17 +0200 Subject: [PATCH 1/5] add very simple integration test * create new rails project * add formtastic * install formtastic * run tests --- .gitignore | 1 + .travis.yml | 4 +++- script/integration-template.rb | 20 ++++++++++++++++++++ script/integration.sh | 12 ++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 script/integration-template.rb create mode 100755 script/integration.sh diff --git a/.gitignore b/.gitignore index 3d5c45fac..60a4efc6c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ Gemfile.lock doc/ tmp gemfiles/*.lock +/dummy/ diff --git a/.travis.yml b/.travis.yml index fbc156b9e..6d83d0785 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,9 @@ gemfile: env: before_install: - gem install bundler --version 1.11.2 -script: "bundle exec rake spec" +script: + - bundle exec rake spec + - script/integration.sh matrix: exclude: - rvm: 1.9.3 diff --git a/script/integration-template.rb b/script/integration-template.rb new file mode 100644 index 000000000..46db67441 --- /dev/null +++ b/script/integration-template.rb @@ -0,0 +1,20 @@ +gem 'formtastic', path: '..' +gem 'bcrypt', '~> 3.1.7' + +in_root do + ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile') +end + +formtastic = -> do + generate(:scaffold, 'user name:string password_digest:string') + generate('formtastic:install') + + rake('db:migrate') +end + +if respond_to?(:after_bundle) # Rails >= 4.2 + after_bundle(&formtastic) +else # Rails 4.1 + run_bundle + formtastic.call +end diff --git a/script/integration.sh b/script/integration.sh new file mode 100755 index 000000000..13922d7b2 --- /dev/null +++ b/script/integration.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +set -e +set -o verbose + +rm -rf dummy + +bundle exec rails new dummy --template=$(dirname "$0")/integration-template.rb --skip-spring --skip-turbolinks + +cd dummy && export BUNDLE_GEMFILE=Gemfile + +bundle exec rake test From 3de555a3ba9c720247e5bf73d0e128b7c78e571c Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Sun, 27 Mar 2016 12:57:13 +0200 Subject: [PATCH 2/5] implement integration test that verifies input types --- script/integration-template.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/script/integration-template.rb b/script/integration-template.rb index 46db67441..1ad2cf487 100644 --- a/script/integration-template.rb +++ b/script/integration-template.rb @@ -1,5 +1,6 @@ gem 'formtastic', path: '..' gem 'bcrypt', '~> 3.1.7' +gem 'rails-dom-testing', group: :test in_root do ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile') @@ -8,8 +9,35 @@ formtastic = -> do generate(:scaffold, 'user name:string password_digest:string') generate('formtastic:install') + generate('formtastic:form', 'user name password:password --force') rake('db:migrate') + + in_root do + inject_into_file 'app/models/user.rb', " has_secure_password\n", after: "< ActiveRecord::Base\n" + inject_into_file 'app/assets/stylesheets/application.css', " *= require formtastic\n", before: ' *= require_self' + inject_into_file 'test/controllers/users_controller_test.rb', <<-RUBY, before: ' test "should get edit" do' + + test "should show form" do + get :edit, id: @user + + assert_select "form" do + assert_select 'li.input.string' do + assert_select 'input#user_name[type=text]' + end + assert_select 'li.input.password' do + assert_select 'input#user_password[type=password]' + end + + assert_select 'fieldset.actions' do + assert_select 'li.action.input_action' do + assert_select 'input[type=submit]' + end + end + end + end + RUBY + end end if respond_to?(:after_bundle) # Rails >= 4.2 From 2909d6d3dc2b2a08dc1a4b7de7d3116f40033d7d Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Sun, 27 Mar 2016 15:51:14 +0200 Subject: [PATCH 3/5] [travis] move bundle cache to the build root --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6d83d0785..70cd45130 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,9 @@ gemfile: - gemfiles/rails_4.1.gemfile - gemfiles/rails_4.2.gemfile - gemfiles/rails_edge.gemfile -env: before_install: - gem install bundler --version 1.11.2 + - export BUNDLE_PATH="${TRAVIS_BUILD_DIR}/vendor/bundle" script: - bundle exec rake spec - script/integration.sh From 23134de8406d2e7b952162623dfa24fcbee1b730 Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Sun, 27 Mar 2016 15:51:32 +0200 Subject: [PATCH 4/5] [travis] speedup integration test by using bundle cache --- script/integration-template.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/script/integration-template.rb b/script/integration-template.rb index 1ad2cf487..76726523c 100644 --- a/script/integration-template.rb +++ b/script/integration-template.rb @@ -2,6 +2,17 @@ gem 'bcrypt', '~> 3.1.7' gem 'rails-dom-testing', group: :test +# to speed up travis install, reuse the bundle path +def bundle_path + File.expand_path ENV.fetch('BUNDLE_PATH', 'vendor/bundle'), ENV['TRAVIS_BUILD_DIR'] +end + +if File.directory?(bundle_path) && bundle_install? + def run_bundle + bundle_command("install --jobs=3 --retry=3 --path=#{bundle_path}") + end +end + in_root do ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile') end From 9a99664a11664399f5ce916ef034ce2c2d2e64da Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Sun, 27 Mar 2016 15:51:51 +0200 Subject: [PATCH 5/5] improve the integration test script --- script/integration.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/script/integration.sh b/script/integration.sh index 13922d7b2..b38a357ef 100755 --- a/script/integration.sh +++ b/script/integration.sh @@ -3,10 +3,15 @@ set -e set -o verbose -rm -rf dummy +test_app=dummy -bundle exec rails new dummy --template=$(dirname "$0")/integration-template.rb --skip-spring --skip-turbolinks +rm -rf ${test_app} -cd dummy && export BUNDLE_GEMFILE=Gemfile +bundle exec rails new ${test_app} \ + --template=$(dirname "$0")/integration-template.rb \ + --skip-spring \ + --skip-turbolinks + +cd ${test_app} && export BUNDLE_GEMFILE=Gemfile bundle exec rake test