129 lines
4.0 KiB
Ruby
129 lines
4.0 KiB
Ruby
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
|
ENV["RAILS_ENV"] ||= 'test'
|
|
require File.expand_path("../../config/environment", __FILE__)
|
|
require 'rspec/rails'
|
|
require 'rspec/matchers'
|
|
require 'capybara/rspec'
|
|
require 'turnip/capybara'
|
|
|
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
# in spec/support/ and its subdirectories.
|
|
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
|
#Dir[Rails.root.join("spec/factories/**/*.rb")].each {|f| require f }
|
|
Dir.glob("spec/acceptance_steps/**/*steps.rb") { |f| load f, true }
|
|
|
|
I18n.locale = Rails.configuration.i18n.default_locale
|
|
Devise.stretches = 1
|
|
Capybara.javascript_driver = :webkit
|
|
#Capybara.default_driver = :selenium
|
|
|
|
module FactoryAttributesFor
|
|
def attributes_for(obj, options={})
|
|
super(obj, options).merge(build(obj).attributes.select{|k,v| k =~ /_id$/}).symbolize_keys
|
|
end
|
|
end
|
|
module SpecSelectorHelpers
|
|
def top_navigation
|
|
'.navbar-fixed-top'
|
|
end
|
|
|
|
# allows tests like:
|
|
# route_should_be 'agama_groups#index'
|
|
def route_should_be(route_def)
|
|
route_hash = case route_def
|
|
when String
|
|
controller_name, action_name = route_def.split('#')
|
|
#action_name = 'index' unless action_name.present?
|
|
{controller: controller_name, action: action_name}
|
|
else
|
|
route_def
|
|
end
|
|
Rails.application.routes.recognize_path(page.current_path).should include route_hash
|
|
end
|
|
|
|
# Uses the click_on method for capybara
|
|
def click_on_translation(key)
|
|
text = I18n.t(key)
|
|
text.should_not =~ /missing/
|
|
click_on text
|
|
end
|
|
|
|
# same as save_and_open_page but with styling
|
|
def show_page
|
|
save_page Rails.root.join( 'public', 'capybara.html' )
|
|
%x(launchy http://localhost:3000/capybara.html)
|
|
end
|
|
end
|
|
RSpec.configure do |config|
|
|
# == Mock Framework
|
|
#
|
|
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
|
#
|
|
# config.mock_with :mocha
|
|
# config.mock_with :flexmock
|
|
# config.mock_with :rr
|
|
config.mock_with :rspec
|
|
config.include FactoryGirl::Syntax::Methods
|
|
config.include FactoryAttributesFor
|
|
config.include Devise::TestHelpers, type: :controller
|
|
config.include EndWithMatcher
|
|
config.include Features::BasicHelpers, type: :feature
|
|
config.include SpecRouteHelpers, type: :feature
|
|
#config.use_transactional_fixtures = true
|
|
config.infer_base_class_for_anonymous_controllers = true
|
|
config.filter_run_excluding broken: true
|
|
config.render_views = true
|
|
|
|
OmniAuth.config.test_mode = true
|
|
OmniAuth.config.add_mock :facebook, {
|
|
info: {
|
|
nickname: 'Joey',
|
|
name: "Facebook Joe",
|
|
first_name: "Facebook Joe"
|
|
},
|
|
credentials: {
|
|
'token' => 'fbAuthToken234',
|
|
'expires_at' => 1.week.from_now.to_i,
|
|
'expires' => true
|
|
},
|
|
uid: '123456790'
|
|
}
|
|
|
|
# Use color in STDOUT
|
|
config.color_enabled = true
|
|
config.fail_fast = false
|
|
|
|
# Use color not only in STDOUT but also in pagers and files
|
|
config.tty = true
|
|
|
|
# Use the specified formatter
|
|
#config.formatter = :documentation # :progress, :html, :textmate
|
|
|
|
# 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 = true
|
|
|
|
config.before :each do
|
|
CouchPotato.couchrest_database.recreate!
|
|
end
|
|
|
|
config.before :each, type: :feature do
|
|
#Supplier.any_instance.stub send_confirmation_instructions: true
|
|
end
|
|
|
|
# If true, the base class of anonymous controllers will be inferred
|
|
# automatically. This will be the default behavior in future versions of
|
|
# rspec-rails.
|
|
#config.infer_base_class_for_anonymous_controllers = true
|
|
def sign_in_user_through_request
|
|
visit "/users/sign_in"
|
|
fill_in 'user[email]', with: @user.email
|
|
fill_in 'user[password]', with: @user.password
|
|
click_on 'Inloggen'
|
|
end
|
|
end
|