-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci] Get a new RSpec based test suite going
Features: * thin helpers for different test scenarios * factory_girl for fixture factories * vcr for mocking the backend * coveralls for coverage tracking * capybara for feature tests
- Loading branch information
1 parent
579e45e
commit a63f6b0
Showing
19 changed files
with
307 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'browser_helper' | ||
|
||
RSpec.feature "<%= class_name.pluralize %>" do | ||
pending "add some scenarios (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Open Build Service Test Suite | ||
This is a test suite based on [RSpec](http://rspec.info/). We are trying to | ||
test things based on the following rules: | ||
|
||
* Every method that isn't private has a unit test (a.k.a. model/controller/helper spec) | ||
* Every main workflow has a feature test | ||
|
||
## Running the spec | ||
`bundle exec rake spec` | ||
|
||
## Directory structure | ||
Conventionally, all tests live under the | ||
|
||
`spec` | ||
|
||
directory and files matching | ||
|
||
`spec/**/*_spec.rb` | ||
|
||
are run by default. Ruby files with custom matchers and macros, etc, belong to | ||
|
||
`spec/support/` | ||
|
||
and its subdirectories. Require them in the individual `*_spec.rb` or `_helper.rb` files. | ||
|
||
## Test types | ||
There are many different [types of specs](https://relishapp.com/rspec/rspec-rails/docs/directory-structure) | ||
possible in RSpec. We concentrate on 4 types: | ||
|
||
* [Model specs](https://relishapp.com/rspec/rspec-rails/docs/model-specs) reside in the `spec/models` directory and test methods in Models. | ||
* [Controller specs](https://relishapp.com/rspec/rspec-rails/docs/controller-specs) reside in the `spec/controllers` directory and test methods in Controllers. | ||
* [Helper specs](https://relishapp.com/rspec/rspec-rails/docs/helper-specs/helper-spec) reside in the `spec/helpers` directory and test methods in Helpers. | ||
* [Feature specs](https://relishapp.com/rspec/rspec-rails/docs/feature-specs/feature-spec) reside in the `spec/features` directory and test workflows through the webui. | ||
|
||
## Adding tests | ||
We are using the standard [RSpec generators](https://relishapp.com/rspec/rspec-rails/docs/generators) like: | ||
|
||
`rails generate rspec:model package` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# as our base helper | ||
require 'rails_helper' | ||
|
||
# for capybara rspec support | ||
require 'capybara' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Webui::ProjectController do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'browser_helper' | ||
|
||
RSpec.feature "Webui::ProjectCreate" do | ||
pending "add some scenarios (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Webui::ProjectHelper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Project do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
ENV['RAILS_ENV'] ||= 'test' | ||
require File.expand_path('../../config/environment', __FILE__) | ||
# Prevent database truncation if the environment is production | ||
abort("The Rails environment is running in production mode!") if Rails.env.production? | ||
# as our base helper | ||
require 'spec_helper' | ||
# for rails | ||
require 'rspec/rails' | ||
# for generating test coverage | ||
require 'simplecov' | ||
# for tracking test coverage on | ||
# https://coveralls.io/github/openSUSE/open-build-service | ||
require 'coveralls' | ||
|
||
# check for pending migration and apply them before tests are run. | ||
ActiveRecord::Migration.maintain_test_schema! | ||
|
||
RSpec.configure do |config| | ||
# load ActiveRecord fixtures | ||
config.fixture_path = "#{::Rails.root}/spec/fixtures" | ||
|
||
# run each example within a transaction | ||
config.use_transactional_fixtures = true | ||
|
||
# set spec type based on their file location | ||
config.infer_spec_type_from_file_location! | ||
|
||
# filter lines from Rails gems in backtraces. | ||
config.filter_rails_from_backtrace! | ||
# arbitrary gems may also be filtered via: | ||
# config.filter_gems_from_backtrace("gem name") | ||
end | ||
|
||
# support test coverage | ||
require 'support/coverage' | ||
|
||
# support fixtures | ||
require 'support/factory_girl' | ||
|
||
# support Suse::backend | ||
require 'support/backend' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# OBS spec helper. See README.md in this directory for details. | ||
# | ||
# WARNING: Given that it is always loaded, you are strongly encouraged to keep | ||
# this file as light-weight as possible! | ||
# Requiring heavyweight dependencies from this file will add to the boot time of | ||
# the test suite on EVERY test run, even for an individual file that may not need | ||
# all of that loaded. Instead, consider making a separate helper file that requires | ||
# the additional dependencies and performs the additional setup, and require it from | ||
# the spec files that actually need it. Exactly this is done in the `rails_helper` | ||
# which loads the complete rails app. | ||
# | ||
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration | ||
RSpec.configure do |config| | ||
# rspec-expectations config goes here. | ||
config.expect_with :rspec do |expectations| | ||
# This option makes the `description` and `failure_message` of custom matchers | ||
# include text for helper methods defined using `chain`, e.g.: | ||
# be_bigger_than(2).and_smaller_than(4).description | ||
# # => "be bigger than 2 and smaller than 4" | ||
# ...rather than: | ||
# # => "be bigger than 2" | ||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
end | ||
|
||
# rspec-mocks config goes here. | ||
config.mock_with :rspec do |mocks| | ||
# Prevents you from mocking or stubbing a method that does not exist on | ||
# a real object. | ||
mocks.verify_partial_doubles = true | ||
end | ||
|
||
# Allows RSpec to persist some state between runs in order to support | ||
# the `--only-failures` and `--next-failure` CLI options. We recommend | ||
# you configure your source control system to ignore this file. | ||
config.example_status_persistence_file_path = "spec/examples.txt" | ||
|
||
# Limits the available syntax to the non-monkey patched syntax that is | ||
# recommended. For more details, see: | ||
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ | ||
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ | ||
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode | ||
config.disable_monkey_patching! | ||
|
||
# Many RSpec users commonly either run the entire suite or an individual | ||
# file, and it's useful to allow more verbose output when running an | ||
# individual spec file. | ||
if config.files_to_run.one? | ||
# Use the documentation formatter for detailed output, | ||
# unless a formatter has already been configured | ||
# (e.g. via a command-line flag). | ||
config.default_formatter = 'doc' | ||
end | ||
|
||
# Print the 10 slowest examples and example groups at the | ||
# end of the spec run, to help surface which specs are running | ||
# particularly slow. | ||
# config.profile_examples = 10 | ||
|
||
# Run specs in random order to surface order dependencies. If you find an | ||
# order dependency and want to debug it, you can fix the order by providing | ||
# the seed, which is printed after each run. | ||
config.order = :random | ||
|
||
# Seed global randomization in this process using the `--seed` CLI option. | ||
# Setting this allows you to use `--seed` to deterministically reproduce | ||
# test failures related to randomization by passing the same `--seed` value | ||
# as the one that triggered the failure. | ||
Kernel.srand config.seed | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'opensuse/backend' | ||
|
||
# Allow connections to localhost | ||
WebMock.disable_net_connect!(allow_localhost: true) | ||
|
||
RSpec.configure do |config| | ||
# build each factory and call #valid? on it | ||
config.before(:suite) do | ||
Suse::Backend.start_test_backend | ||
end | ||
end | ||
|
||
# for mocking the backend | ||
require 'support/vcr' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Capybara.default_wait_time = 6 | ||
Capybara.save_and_open_page_path = Rails.root.join('tmp', 'capybara') | ||
|
||
Capybara.register_driver :poltergeist do |app| | ||
Capybara::Poltergeist::Driver.new(app, debug: false, timeout: 30) | ||
end | ||
|
||
Capybara.register_driver :rack_test do |app| | ||
Capybara::RackTest::Driver.new(app, headers: {'HTTP_ACCEPT' => 'text/html'}) | ||
end | ||
|
||
Capybara.javascript_driver = :poltergeist | ||
|
||
# Automatically save the page a test fails | ||
RSpec.configure do |config| | ||
config.after(:each, type: :feature) do | ||
example_filename = RSpec.current_example.full_description | ||
example_filename = example_filename.gsub ' ', '_' | ||
example_filename = example_filename + '.html' | ||
example_filename = File.expand_path(example_filename, Capybara.save_and_open_page_path) | ||
if RSpec.current_example.exception.present? | ||
save_page(example_filename) | ||
else | ||
# remove the file if the test starts working again | ||
if File.exist?(example_filename) | ||
File.unlink(example_filename) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# start coverage tracking | ||
Coveralls.wear_merged!('rails') | ||
|
||
# SimpleCov configuration | ||
SimpleCov.start 'rails' do | ||
add_filter '/app/indices/' | ||
add_filter '/app/models/user_ldap_strategy.rb' | ||
merge_timeout 3600 | ||
formatter Coveralls::SimpleCov::Formatter | ||
end |
Oops, something went wrong.