Skip to content

Commit

Permalink
Merge pull request #41 from inz/support/integration-test-suite
Browse files Browse the repository at this point in the history
Setup integration test suite
  • Loading branch information
inz committed Mar 21, 2016
2 parents d070e09 + 696aefb commit c68ea10
Show file tree
Hide file tree
Showing 40 changed files with 4,745 additions and 205 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@

# Ignore .idea directory (Rubymine)
/.idea

# Ignore simplecov coverage report
/coverage/

# Ignore wercker build files
/_builds/
/_cache/
/_projects/
/_steps/

# Ignore Capybara page savings from IT debugging
/public/capybara
36 changes: 36 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config
# Maybe put some conditional here not to execute the code below unless ENV['COVERAGE'] == 'true'
SimpleCov.start do
# see https://github.com/colszowka/simplecov/blob/master/lib/simplecov/defaults.rb
load_profile 'test_frameworks'
coverage_dir 'coverage'
command_name 'MiniTest'
merge_timeout 3600 # 1 hour
track_files "{app,lib}/**/*.rb"

# Groups
add_group 'Controllers', 'app/controllers'
add_group 'Models', 'app/models'
# add_group 'Mailers', 'app/mailers'
add_group 'Helpers', 'app/helpers'
add_group 'Jobs', %w(app/jobs app/workers)
# add_group 'Libraries', 'lib'

add_group 'Provider updater', 'app/provider_updater'
add_group 'Long files' do |src_file|
src_file.lines.count > 100
end
class MaxLinesFilter < SimpleCov::Filter
def matches?(source_file)
source_file.lines.count < filter_argument
end
end
add_group 'Short files', MaxLinesFilter.new(5)

# Exclude these paths from analysis
add_filter '/config/'
add_filter '/db/'
add_filter 'lib/plugins'
add_filter 'vendor'
add_filter 'bundle'
end
29 changes: 28 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,31 @@
You should also periodically push your topic branches during development. That
way, there will always be a reasonably current backup of your work in the
upstream repository, and the whole team can get a feel on what others are
working on.
working on.

## Tips and Tricks

* Continuous test execution and live reload:

```
bundle exec guard
```

* Automatically runs affected tests on file edit. Type `all` to manually run all tests.
* Automatically reloads a page on asset modification via the following browser plugin: http://livereload.com/extensions/

* Save a snapshot of the page during an integration test:

```
show_page
```

* Test Wercker CI build locally

```
wercker build
```

* Requires wercker CLI: http://wercker.com/cli/
* Use `--attach-on-error` to debug failing builds
* Use `--docker-local` to use locally cached containers
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ group :development, :test do
gem 'byebug'
gem 'quiet_assets'
gem 'webmock'

gem 'minitest-reporters'
gem 'simplecov', require: false

# Acceptance test framework for web applications: https://github.com/jnicklas/capybara
gem 'capybara'
# Support headless UI tests; Requires PhantomJS: http://phantomjs.org/
gem 'poltergeist'
# Different DB cleaning strategy is required for Javascript UI tests running in a separate thread
gem 'database_cleaner'
# Fixtures replacement for integration tests
gem 'factory_girl_rails'
end

group :development do
Expand Down
45 changes: 44 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
ansi (1.5.0)
arel (6.0.3)
autoprefixer-rails (6.3.1)
execjs
Expand All @@ -53,6 +54,14 @@ GEM
thor (~> 0.19)
builder (3.2.2)
byebug (8.2.2)
capybara (2.6.2)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
cliver (0.3.2)
coderay (1.1.0)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
Expand All @@ -64,18 +73,25 @@ GEM
concurrent-ruby (1.0.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
database_cleaner (1.5.1)
debug_inspector (0.0.2)
delayed_job (4.1.1)
activesupport (>= 3.0, < 5.0)
delayed_job_active_record (4.1.0)
activerecord (>= 3.0, < 5)
delayed_job (>= 3.0, < 5)
docile (1.1.5)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
erubis (2.7.0)
eventmachine (1.0.9.1)
execjs (2.6.0)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.6.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
ffi (1.9.10)
font-awesome-sass (4.5.0)
sass (>= 3.2)
Expand Down Expand Up @@ -147,9 +163,14 @@ GEM
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.99)
mime-types (2.99.1)
mini_portile2 (2.0.0)
minitest (5.8.4)
minitest-reporters (1.1.8)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
multi_json (1.11.2)
nenv (0.3.0)
nokogiri (1.6.7.2)
Expand All @@ -161,6 +182,11 @@ GEM
rack
rake (>= 0.8.1)
pg (0.18.4)
poltergeist (1.9.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
Expand Down Expand Up @@ -215,6 +241,7 @@ GEM
json (~> 1.4)
redcarpet (3.3.4)
ref (2.0.0)
ruby-progressbar (1.7.5)
ruby_parser (3.7.3)
sexp_processor (~> 4.1)
safe_yaml (1.0.4)
Expand All @@ -230,6 +257,11 @@ GEM
rdoc (~> 4.0)
sexp_processor (4.6.1)
shellany (0.0.1)
simplecov (0.11.2)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
spring (1.6.3)
sprockets (3.5.2)
Expand Down Expand Up @@ -263,6 +295,11 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
websocket-driver (0.6.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.0.0)
nokogiri (~> 1.3)

PLATFORMS
ruby
Expand All @@ -272,8 +309,11 @@ DEPENDENCIES
bootstrap (~> 4.0.0.alpha3)
bourbon
byebug
capybara
coffee-rails (~> 4.1.0)
database_cleaner
delayed_job_active_record
factory_girl_rails
font-awesome-sass (~> 4.5.0)
guard
guard-bundler
Expand All @@ -285,8 +325,10 @@ DEPENDENCIES
jbuilder (~> 2.0)
jquery-rails
kaminari
minitest-reporters
passenger
pg
poltergeist
quiet_assets
rack-livereload
rails (~> 4.2.4)
Expand All @@ -297,6 +339,7 @@ DEPENDENCIES
redcarpet
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simplecov
spring
sqlite3
terminal-notifier-guard
Expand Down
2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ guard :bundler do
files.each { |file| watch(helper.real_path(file)) }
end

guard :minitest do
guard :minitest, spring: true do
# with Minitest::Unit
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
Expand Down
4 changes: 3 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ specifications and requirements.
<code>rbenv install $(cat cloud-stove/.ruby-version)</code>.

For RVM, run <code>rvm install $(cat cloud-stove/.ruby-version)</code>.


* Install `phantomjs` for headless UI tests: http://phantomjs.org/download.html

* Set up dependencies and database
cd cloud-stove
bin/setup
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_main_navigation.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
%button.btn.btn-link.nav-link.dropdown-toggle{data: { toggle: 'dropdown' }}
-# = icon 'user'
%span.hidden-sm-down Arthur Dent
= image_tag "//www.gravatar.com/avatar/#{Digest::MD5.hexdigest('inzinger@gmail.com')}", class: 'avatar'
= image_tag "//#{Rails.configuration.x.gravatar_host}/avatar/#{Digest::MD5.hexdigest('inzinger@gmail.com')}", class: 'avatar'
.dropdown-menu.dropdown-menu-right
= link_to icon('user', t('.my_account')), root_path, class: 'dropdown-item'
.dropdown-divider
Expand Down
4 changes: 4 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ class Application < Rails::Application
config.active_record.raise_in_transactional_callbacks = true

config.active_job.queue_adapter = :delayed_job

# Custom configuration using the recommended `config.x` property:
# http://guides.rubyonrails.org/configuring.html#custom-configuration
config.x.gravatar_host = 'www.gravatar.com'
end
end
7 changes: 7 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false

# Serve assets for JS-enabled tests and enable debug mode
config.assets.enabled = true
config.assets.debug = true

# Configure static file server for tests with Cache-Control for performance.
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'
Expand Down Expand Up @@ -39,4 +43,7 @@

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

# Custom Cloud Stove config
config.x.gravatar_host = 'localhost:3000'
end
18 changes: 18 additions & 0 deletions lib/tasks/factory_girl.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Recommended way to lint factories to avoid performance overhead if running few tests
# https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#linting-factories
# Usage: `rake factory_girl:lint`
namespace :factory_girl do
desc 'Verify that all FactoryGirl factories are valid'
task lint: :environment do
if Rails.env.test?
begin
DatabaseCleaner.start
FactoryGirl.lint
ensure
DatabaseCleaner.clean_with :transaction
end
else
system("bundle exec rake factory_girl:lint RAILS_ENV='test'")
end
end
end
7 changes: 7 additions & 0 deletions lib/tasks/simplecov.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Usage: `rake test:coverage`
namespace :test do
task :coverage do
require 'simplecov'
Rake::Task['test'].execute
end
end
2 changes: 1 addition & 1 deletion test/controllers/blueprints_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class BlueprintsControllerTest < ActionController::TestCase
setup do
@blueprint = blueprints(:one)
@blueprint = create(:blueprint)
end

test "should get index" do
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/cloud_applications_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class CloudApplicationsControllerTest < ActionController::TestCase
setup do
@cloud_application = cloud_applications(:one)
@cloud_application = create(:cloud_application)
end

test "should get index" do
Expand All @@ -24,7 +24,7 @@ class CloudApplicationsControllerTest < ActionController::TestCase
end

test "should get new for instance from blueprint" do
blueprint = blueprints(:multitier_app)
blueprint = create(:mt_blueprint)
get :new, blueprint: blueprint.id
assert_response :success
assert_not_nil @controller.params[:blueprint]
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/components_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ComponentsControllerTest < ActionController::TestCase

setup do
@component = components(:one)
@component = create(:component)
end

test "should get index" do
Expand Down
Loading

0 comments on commit c68ea10

Please sign in to comment.