Merge pull request #2 from CodeforLeipzig/use-rspec

Use rspec
This commit is contained in:
Lars Mai 2016-02-24 19:54:59 +01:00
commit 424cc0bf46
30 changed files with 528 additions and 76 deletions

2
.rspec Normal file
View file

@ -0,0 +1,2 @@
--color
--require spec_helper

View file

@ -39,11 +39,15 @@ gem 'sdoc', '~> 0.4.0', group: :doc
group :development do
gem 'spring'
gem 'spring-commands-rspec'
gem 'quiet_assets'
gem 'awesome_print'
gem 'guard-rspec', require: false
# gem 'terminal-notifier-guard' # FIXME cross-platform
end
group :development, :test do
gem 'rspec-rails', '~> 3.0'
gem 'pry'
gem 'pry-rails'
gem 'capybara'
@ -52,9 +56,11 @@ end
group :test do
gem 'factory_girl_rails'
gem 'shoulda'
gem 'shoulda-matchers', '~> 3.1'
gem 'faker'
gem 'simplecov', require: false
gem 'test_after_commit' # TODO remove when moving to rails 5
gem 'database_cleaner'
end
# Use ActiveModel has_secure_password

View file

@ -54,6 +54,8 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.9.1.1)
database_cleaner (1.5.1)
diff-lcs (1.2.5)
docile (1.1.5)
elasticsearch (1.0.8)
elasticsearch-api (= 1.0.7)
@ -79,11 +81,27 @@ GEM
i18n (~> 0.5)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
ffi (1.9.10)
formatador (0.2.5)
foundation-rails (5.5.1.2)
railties (>= 3.1.0)
sass (>= 3.3.0, < 3.5)
globalid (0.3.5)
activesupport (>= 4.1.0)
guard (2.13.0)
formatador (>= 0.2.4)
listen (>= 2.7, <= 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.6.4)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashie (3.4.1)
i18n (0.7.0)
jquery-rails (4.0.3)
@ -99,8 +117,12 @@ GEM
rails
launchy (2.4.3)
addressable (~> 2.3)
listen (3.0.6)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9.7)
loofah (2.0.1)
nokogiri (>= 1.5.9)
lumberjack (1.0.10)
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
@ -109,8 +131,12 @@ GEM
minitest (5.6.0)
multi_json (1.11.0)
multipart-post (2.0.0)
nenv (0.3.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
notiffany (0.0.8)
nenv (~> 0.1)
shellany (~> 0.0)
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
@ -157,8 +183,32 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
rdoc (4.2.0)
json (~> 1.4)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-rails (3.3.3)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
sass (3.4.13)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
@ -169,12 +219,9 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-context (1.2.1)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
shellany (0.0.1)
shoulda-matchers (3.1.1)
activesupport (>= 4.0.0)
simplecov (0.11.1)
docile (~> 1.1.0)
json (~> 1.8)
@ -191,6 +238,8 @@ GEM
slim (~> 3.0)
slop (3.6.0)
spring (1.3.4)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
sprockets (3.0.2)
rack (~> 1.0)
sprockets-rails (2.2.4)
@ -199,6 +248,8 @@ GEM
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10)
temple (0.7.5)
test_after_commit (0.4.2)
activerecord (>= 3.2)
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
@ -222,12 +273,14 @@ DEPENDENCIES
awesome_print
capybara
coffee-rails
database_cleaner
elasticsearch
elasticsearch-dsl
elasticsearch-model
factory_girl_rails
faker
foundation-rails
guard-rspec
jquery-rails
kaminari
kaminari-i18n
@ -239,13 +292,16 @@ DEPENDENCIES
quiet_assets
rails
rails-i18n
rspec-rails (~> 3.0)
sass-rails
sdoc (~> 0.4.0)
shoulda
shoulda-matchers (~> 3.1)
simplecov
slim-rails
spring
spring-commands-rspec
sqlite3
test_after_commit
turbolinks
uglifier
validate_url

70
Guardfile Normal file
View file

@ -0,0 +1,70 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
# Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'
guard :rspec, cmd: "bin/rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
# Feel free to open issues for suggestions and improvements
# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)
# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)
watch(rails.controllers) do |m|
[
rspec.spec.("routing/#{m[1]}_routing"),
rspec.spec.("controllers/#{m[1]}_controller"),
rspec.spec.("acceptance/#{m[1]}")
]
end
# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
end

View file

@ -1,4 +1,17 @@
.search-result {
border-bottom: 1px solid $table-border-color;
padding-bottom: 0.25em;
margin-bottom: 1.2em;
}
.search-result article {
line-height: normal;
}
.search-result h4 {
line-height: normal;
font-size: 1.2rem;
margin-bottom: 0.1rem;
}
.search-result .metainfo {
font-size: 0.8rem;
}

View file

@ -7,7 +7,7 @@ end
class SearchController < ApplicationController
def index
@search_definition = params[:paper_search].present? ? PaperSearch.new(search_params) : PaperSearch.new
@search_definition = PaperSearch.new(search_params)
@search_definition.sort_by ||= "score"
execute_search
@ -29,7 +29,7 @@ class SearchController < ApplicationController
end
def search_params
params.require(:paper_search).permit(:query, :paper_type, :originator, :sort_by)
params.fetch(:paper_search, {}).permit(:query, :paper_type, :originator, :sort_by)
end
def extract_facets(name)

View file

@ -13,7 +13,7 @@ module SearchHelper
def filter_select(builder, name, desc, facets, selected)
capture do
concat(label name, desc)
concat(builder.label name, desc)
concat(
builder.select name,
options_from_collection_for_select(facets, :term, :term_with_count, selected),

View file

@ -19,6 +19,8 @@ class Paper < ActiveRecord::Base
validates :published_at, presence: true, parseable_date: true
validates :resolution, length: { maximum: 30_000 }
index_name ['srm', Rails.env, self.base_class.to_s.pluralize.underscore].join('_')
settings index: { number_of_shards: 1 } do
mappings dynamic: false do
indexes :name, type: :string, analyzer: "german"

View file

@ -1,12 +1,12 @@
= paginator.render do
.pagination-centered
ul.pagination
= first_page_tag unless current_page.first?
= prev_page_tag unless current_page.first?
== first_page_tag unless current_page.first?
== prev_page_tag unless current_page.first?
- each_page do |page|
- if page.left_outer? || page.right_outer? || page.inside_window?
= page_tag page
== page_tag page
- elsif !page.was_truncated?
= gap_tag
= next_page_tag unless current_page.last?
= last_page_tag unless current_page.last?
== gap_tag
== next_page_tag unless current_page.last?
== last_page_tag unless current_page.last?

View file

@ -1,20 +1,20 @@
doctype html
html
head
title Stadtratmonitor Leipzig
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'vendor/modernizr'
= csrf_meta_tags
head
title Stadtratmonitor Leipzig
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'vendor/modernizr'
= csrf_meta_tags
body
.row
.small-12.columns
.clearfix
.right = render 'login_button'
h1#title = link_to 'Stadtratmonitor Leipzig', root_path
- flash.each do |name, msg|
= content_tag :div, msg, class: name
= yield
body
.row
.small-12.columns
.clearfix
.right = render 'login_button'
h1#title = link_to 'Stadtratmonitor Leipzig', root_path
- flash.each do |name, msg|
= content_tag :div, msg, class: name
= yield
script src="https://login.persona.org/include.js"
= javascript_include_tag 'application', 'data-turbolinks-track' => true
script src="https://login.persona.org/include.js"
= javascript_include_tag 'application', 'data-turbolinks-track' => true

View file

@ -1,14 +1,6 @@
div
= render 'search/form'
- if false # params[:q].present?
.row
.small-4.columns
= facet_list(@paper_type_facets)
.small-4.columns.end
= facet_list(@originator_facets)
.clearfix
- if params[:q].present?
.left
@ -18,18 +10,18 @@ div
- else
| #{@papers.total} Dokumente in der Datenbank
div
ul.no-bullet
ul.no-bullet#search_results
- @papers.each do |doc|
li.search-result
small = doc.paper_type
'
small = doc.originator
'
small = l doc.published_at.to_date
'
small = doc._score
= link_to doc.url, target: '_blank' do
div = doc.name
article
h4 = link_to doc.name, doc.url, target: '_blank'
div.metainfo
span.paper_type = doc.paper_type
'
span.originator = doc.originator
'
span.published = l doc.published_at.to_date
/! score: #{doc._score}
div
div#pagination
= paginate @papers

7
bin/rspec Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require 'bundler/setup'
load Gem.bin_path('rspec-core', 'rspec')

View file

@ -1,17 +1,14 @@
#!/usr/bin/env ruby
# This file loads spring without using Bundler, in order to be fast
# It gets overwritten when you run the `spring binstub` command
# This file loads spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.
unless defined?(Spring)
require "rubygems"
require "bundler"
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
ENV["GEM_HOME"] = ""
Gem.paths = ENV
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)
Gem.paths = { "GEM_PATH" => [Bundler.bundle_path.to_s, *Gem.path].uniq }
gem "spring", match[1]
require "spring/binstub"
end

View file

@ -13,7 +13,7 @@ Rails.application.configure do
config.eager_load = false
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'
# Show full error reports and disable caching.

View file

View file

@ -0,0 +1,33 @@
require 'rails_helper'
RSpec.describe SearchController, type: :controller, elasticsearch: true do
describe "GET #index" do
it "returns http success" do
get :index, body: 'leipzig'
expect(response).to have_http_status(:success)
end
it "assigns @search_definition with default sort order" do
search = PaperSearch.new(sort_by: 'score')
get :index, body: 'leipzig'
expect(assigns(:search_definition).attributes).to eq(search.attributes)
end
it "renders the index template" do
get :index, body: 'leipzig'
expect(response).to render_template(:index)
end
it "executes the search with PaperSearch parameters" do
pending("simplify search implementation")
result_page = double("page", results: []) # MEH
response = double("es_response", page: result_page)
expect(Paper).to receive(:search).and_return(response)
get :index, body: 'leipzig'
end
end
end

16
spec/factories/papers.rb Normal file
View file

@ -0,0 +1,16 @@
require_relative '../factory_helper'
FactoryGirl.define do
factory :paper do
name { Faker::Lorem.sentence }
sequence(:url) { |n| Faker::Internet.url("ris.example.org", "/paper-#{n}.html") }
sequence(:reference) { |n| FactoryHelper.reference(n) }
body "leipzig"
published_at "2015-07-20 21:16:53"
scraped_at "2015-07-20 21:16:53"
paper_type { FactoryHelper.paper_type }
originator { Faker::Name.name }
resolution { Faker::Lorem.paragraph(3) }
content "-------------------------------\n\n " # oh well...
end
end

29
spec/factory_helper.rb Normal file
View file

@ -0,0 +1,29 @@
module FactoryHelper
PAPER_TYPES = [
"Verwaltungsstandpunkt",
"Anfrage",
"Beschlussvorlage",
"Änderungsantrag",
"Antrag",
"Neufassung",
"Informationsvorlage",
"Einwohneranfrage",
"Petition",
"schriftliche Antwort zur Anfrage",
"Wichtige Angelegenheit",
"Eilentscheidung",
"Dringliche Anfrage"
]
def self.paper_type
PAPER_TYPES.sample
end
REFERENCE = "A-%05i/16"
def self.reference(seq)
REFERENCE % seq
end
end

View file

@ -0,0 +1,56 @@
require 'rails_helper'
RSpec.feature "Basic search", type: :feature, elasticsearch: true do
before(:each) do
@papers = FactoryGirl.create_list(:paper, 11)
Paper.__elasticsearch__.refresh_index!
end
scenario "It displays the search form" do
visit search_path body: "leipzig"
expect(page).to have_content("Stadtratmonitor")
expect(page).to have_field("paper_search_query")
expect(page).to have_select("Typ")
expect(page).to have_select("Einreicher")
expect(page).to have_selector("label", text: "Sortierung")
expect(page).to have_field("paper_search_sort_by_date", type: "radio")
expect(page).to have_field("paper_search_sort_by_score", type: "radio")
end
scenario "With empty query displays all documents" do
visit search_path body: "leipzig"
expect(page).to have_selector("ul#search_results")
expect(page).to have_content("#{@papers.size} Dokumente in der Datenbank")
end
scenario "Search results are paginated" do
visit search_path body: "leipzig"
expect(page).to have_css("li.search-result", count: 10)
expect(page).to have_css("div#pagination")
within("div#pagination") do
expect(page).to have_css("li", count: 4) # two pages + next + last
expect(page).to have_css("li.current", text: "1")
expect(page).to have_link("2")
expect(page).to have_link("Weiter")
expect(page).to have_link("Ende")
end
page.find("div#pagination").click_link("2")
expect(page).to have_css("li.search-result", count: 1)
within("div#pagination") do
expect(page).to have_css("li.current", text: "2")
end
end
scenario "Search results have basic information" do
visit search_path body: "leipzig"
paper = @papers.first
result = page.find("li.search-result", match: :first)
expect(result).to have_link(paper.name, href: paper.url)
expect(result).to have_css("span.paper_type", text: paper.paper_type)
expect(result).to have_css("span.originator", text: paper.originator)
expect(result).to have_css("span.published", text: I18n.l(paper.published_at.to_date))
end
end

0
spec/helpers/.gitkeep Normal file
View file

0
spec/models/.gitkeep Normal file
View file

View file

@ -0,0 +1,7 @@
require 'rails_helper'
RSpec.describe Paper do
context "Validations" do
it { should validate_presence_of(:name) }
end
end

52
spec/rails_helper.rb Normal file
View file

@ -0,0 +1,52 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
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?
require 'spec_helper'
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
# 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 = false
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
end

0
spec/requests/.gitkeep Normal file
View file

92
spec/spec_helper.rb Normal file
View file

@ -0,0 +1,92 @@
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your 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.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It 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. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# 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://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
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.
# --seed 1234
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
end

View file

@ -0,0 +1,22 @@
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, type: :feature) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.append_after(:each) do
DatabaseCleaner.clean
end
end

View file

@ -0,0 +1,5 @@
RSpec.configure do |config|
config.before :each, elasticsearch: true do
Paper.__elasticsearch__.create_index!(force: true)
end
end

View file

@ -0,0 +1,3 @@
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end

6
spec/support/shoulda.rb Normal file
View file

@ -0,0 +1,6 @@
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end

View file

@ -1,14 +0,0 @@
FactoryGirl.define do
factory :paper do
name Faker::Lorem.sentence
url Faker::Internet.url("example-ris.de")
reference "MyString"
body "leipzig"
published_at "2015-07-20 21:16:53"
scraped_at "2015-07-20 21:16:53"
paper_type "Verwaltungsstandpunkt"
originator Faker::Name.name
resolution Faker::Lorem.paragraph(3)
content "-------------------------------\n\n " # oh well...
end
end