19 |
20 |
21 | EOP
22 |
23 | run ->(env) { ['200', {'Content-Type' => 'text/html'}, [html_page]] }
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/bbq-rails/lib/bbq/rails/railtie.rb:
--------------------------------------------------------------------------------
1 | require 'rails/railtie'
2 | require 'rails/generators'
3 | require 'bbq/core'
4 |
5 | module Bbq
6 | module Rails
7 | class Railtie < ::Rails::Railtie
8 |
9 | initializer "bqq.set_app" do
10 | Bbq::Core.app = ::Rails.application
11 | end
12 |
13 | rake_tasks do
14 | load File.expand_path(File.join(File.dirname(__FILE__), '../../tasks/bbq.rake'))
15 | end
16 |
17 | helper_generators = %w(test_unit rspec).flat_map do |test_framework|
18 | ["#{test_framework}:bbq_test", "#{test_framework}:bbq_install"]
19 | end
20 | ::Rails::Generators.hide_namespaces *helper_generators
21 |
22 | end
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/bbq-devise/README.md:
--------------------------------------------------------------------------------
1 | # Bbq::Devise
2 |
3 | TODO: Write a gem description
4 |
5 | ## Installation
6 |
7 | Add this line to your application's Gemfile:
8 |
9 | ```ruby
10 | gem 'bbq-devise'
11 | ```
12 |
13 | And then execute:
14 |
15 | $ bundle
16 |
17 | Or install it yourself as:
18 |
19 | $ gem install bbq-devise
20 |
21 | ## Usage
22 |
23 | TODO: Write usage instructions here
24 |
25 | ## Contributing
26 |
27 | 1. Fork it ( https://github.com/[my-github-username]/bbq-devise/fork )
28 | 2. Create your feature branch (`git checkout -b my-new-feature`)
29 | 3. Commit your changes (`git commit -am 'Add some feature'`)
30 | 4. Push to the branch (`git push origin my-new-feature`)
31 | 5. Create a new Pull Request
32 |
--------------------------------------------------------------------------------
/bbq-rspec/spec/test_user_matchers_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | class TestUserWithMatchers < Bbq::Core::TestUser
4 | def ensure_no_red_ponycorns
5 | expect(self).to have_no_content('Red')
6 | end
7 |
8 | def ensure_pink_ponycorns
9 | expect(self).to see('Pink').within('#unicorns')
10 | end
11 | end
12 |
13 | describe 'TestUser matchers' do
14 |
15 | specify 'capybara matcher' do
16 | user = TestUserWithMatchers.new
17 | user.visit('/test_page')
18 |
19 | expect { user.ensure_no_red_ponycorns }.not_to raise_error
20 | end
21 |
22 | specify 'bbq matcher' do
23 | user = TestUserWithMatchers.new
24 | user.visit('/test_page')
25 |
26 | expect { user.ensure_pink_ponycorns }.not_to raise_error
27 | end
28 |
29 | end
30 |
--------------------------------------------------------------------------------
/bbq-core/test/util_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 | require 'bbq/core/util'
3 |
4 | class User
5 | module Commenter
6 | end
7 | end
8 |
9 | module Commenter
10 | end
11 |
12 | class UtilTest < Minitest::Test
13 |
14 | def test_find_module_in_object_namespace
15 | assert_commenter(User.new, User::Commenter)
16 | end
17 |
18 | def test_find_module_in_class_namespace
19 | assert_commenter(User, User::Commenter)
20 | end
21 |
22 | def test_find_module_in_string_namespace
23 | assert_commenter("User", User::Commenter)
24 | end
25 |
26 | def test_find_global_module
27 | assert_commenter(nil, ::Commenter)
28 | end
29 |
30 | def assert_commenter(namespace, result)
31 | [:commenter, "commenter"].each do |name|
32 | assert_equal Bbq::Core::Util.find_module(name, namespace), result
33 | end
34 | end
35 |
36 | end
37 |
--------------------------------------------------------------------------------
/bbq-devise/test/bbq_devise_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 | require 'bbq/core/test_user'
3 | require 'bbq/devise'
4 |
5 | class DeviseTestUser < Bbq::Core::TestUser
6 | include Bbq::Devise
7 | end
8 |
9 | class BbqDeviseTest < Minitest::Unit::TestCase
10 |
11 | def test_user_register
12 | user = DeviseTestUser.new
13 | user.register
14 |
15 | assert user.see?("dummy")
16 | User.find_by_email(user.email).destroy
17 | end
18 |
19 | def test_login_user
20 | user = DeviseTestUser.new(:password => 'dupa.8')
21 | user.register
22 | user.logout
23 | user.login
24 |
25 | assert user.see?("dummy")
26 | User.find_by_email(user.email).destroy
27 | end
28 |
29 | def test_user_without_login
30 | user = DeviseTestUser.new
31 | user.visit user.root_path
32 |
33 | assert user.not_see?("dummy")
34 | end
35 |
36 | end
37 |
--------------------------------------------------------------------------------
/bbq/lib/bbq/test_unit.rb:
--------------------------------------------------------------------------------
1 | require 'bbq/core/session'
2 | require 'test/unit'
3 | require 'test/unit/assertions'
4 | require 'active_support/test_case'
5 |
6 | module Bbq
7 | class TestCase < ActiveSupport::TestCase
8 | class << self
9 | alias :scenario :test
10 | alias :background :setup
11 | end
12 |
13 | alias :background :setup
14 |
15 | teardown do
16 | Bbq::Core::Session.pool.release
17 | end
18 | end
19 |
20 | class TestUser
21 | include Test::Unit::Assertions
22 |
23 | def see!(*args)
24 | args.each do |arg|
25 | assert has_content?(arg), "Expecting to see \"#{arg}\", text not found."
26 | end
27 | end
28 |
29 | def not_see!(*args)
30 | args.each do |arg|
31 | assert has_no_content?(arg), "Found \"#{arg}\", which was unexpected."
32 | end
33 | end
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/bbq-devise/test/dummy/db/schema.rb:
--------------------------------------------------------------------------------
1 | ActiveRecord::Schema.define(:version => 20110521153145) do
2 | create_table "users", :force => true do |t|
3 | t.string "email", :default => "", :null => false
4 | t.string "encrypted_password", :limit => 128, :default => "", :null => false
5 | t.string "reset_password_token"
6 | t.datetime "reset_password_sent_at"
7 | t.datetime "remember_created_at"
8 | t.integer "sign_in_count", :default => 0
9 | t.datetime "current_sign_in_at"
10 | t.datetime "last_sign_in_at"
11 | t.string "current_sign_in_ip"
12 | t.string "last_sign_in_ip"
13 | t.datetime "created_at"
14 | t.datetime "updated_at"
15 | end
16 |
17 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true
18 | add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
19 | end
20 |
--------------------------------------------------------------------------------
/bbq-rails/test/bbq_test_generator_test.rb:
--------------------------------------------------------------------------------
1 | require "test_helper"
2 | require "rails/generators/test_case"
3 | require "generators/bbq/test_generator"
4 |
5 | class BbqTestGeneratorTest < ::Rails::Generators::TestCase
6 | destination File.expand_path(File.join(File.dirname(__FILE__), '../tmp'))
7 | setup :prepare_destination
8 |
9 | tests Bbq::TestGenerator
10 |
11 | def test_creating_test_unit_feature_file
12 | run_generator %w(MySuperThing -t test_unit)
13 |
14 | assert_file "test/acceptance/my_super_thing_test.rb", /class MySuperThingTest < Bbq::TestCase/
15 | assert_file "test/acceptance/my_super_thing_test.rb", /require "test_helper"/
16 | end
17 |
18 | def test_creating_rspec_feature_file
19 | run_generator %w(MySuperThing -t rspec)
20 |
21 | assert_file "spec/acceptance/my_super_thing_spec.rb", /feature "My super thing" do/
22 | assert_file "spec/acceptance/my_super_thing_spec.rb", /require "spec_helper"/
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/bbq-core/lib/bbq/core/test_user.rb:
--------------------------------------------------------------------------------
1 | require 'bbq/core/session'
2 | require 'bbq/core/roles'
3 | require 'bbq/core/test_user/capybara_dsl'
4 | require 'bbq/core/test_user/eyes'
5 | require 'bbq/core/test_user/within'
6 |
7 | module Bbq
8 | module Core
9 | class TestUser
10 | include Bbq::Core::TestUser::CapybaraDsl
11 | include Bbq::Core::TestUser::Eyes
12 | include Bbq::Core::TestUser::Within
13 | include Bbq::Core::Roles
14 |
15 | attr_reader :options
16 |
17 | def initialize(options = {})
18 | @options = default_options.merge(options)
19 | end
20 |
21 | def default_options
22 | {
23 | :pool => Bbq::Core::Session.pool,
24 | :driver => ::Capybara.default_driver
25 | }
26 | end
27 |
28 | def page
29 | @page ||= options[:session] || Bbq::Core::Session.next(:driver => options[:driver], :pool => options[:pool])
30 | end
31 | end
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/bbq-rspec/bbq-rspec.gemspec:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 | lib = File.expand_path("../lib", __FILE__)
3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4 | require "bbq/rspec/version"
5 |
6 | Gem::Specification.new do |spec|
7 | spec.name = "bbq-rspec"
8 | spec.version = Bbq::RSpec::VERSION
9 | spec.authors = ["DRUG - Dolnośląska Grupa Użytkowników Ruby"]
10 | spec.email = ["bbq@drug.org.pl"]
11 | spec.summary = %q{RSpec integration for bbq.}
12 | spec.description = %q{RSpec integration for bbq.}
13 | spec.homepage = ""
14 | spec.license = "MIT"
15 |
16 | spec.files = `git ls-files -z`.split("\x0")
17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19 | spec.require_paths = ["lib"]
20 |
21 | spec.add_dependency "bbq-core", "= 0.4.0"
22 |
23 | spec.add_development_dependency "rake"
24 | spec.add_development_dependency "rspec", ">= 3.0"
25 | end
26 |
--------------------------------------------------------------------------------
/bbq-core/test/test_client_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 | require 'bbq/core/test_client'
3 |
4 | class TestClientTest < Minitest::Test
5 |
6 | def test_rack_test_to_env_headers_for_empty_hash
7 | test_client = Bbq::Core::TestClient::RackTest.new(:app)
8 | assert_equal({}, test_client.to_env_headers({}))
9 | end
10 |
11 | def test_rack_test_to_env_headers_for_content_type_or_content_length
12 | test_client = Bbq::Core::TestClient::RackTest.new(:app)
13 | result = test_client.to_env_headers({
14 | "content-type" => "text/plain",
15 | "content-length" => "40"
16 | })
17 | assert_includes(result.keys, "CONTENT_TYPE")
18 | assert_includes(result.keys, "CONTENT_LENGTH")
19 | end
20 |
21 | def test_rack_test_to_env_headers_for_other_headers
22 | test_client = Bbq::Core::TestClient::RackTest.new(:app)
23 | result = test_client.to_env_headers({
24 | "silly-header" => "silly-value"
25 | })
26 | assert_includes(result.keys, "HTTP_SILLY_HEADER")
27 | end
28 |
29 | end
30 |
31 |
--------------------------------------------------------------------------------
/bbq-core/lib/bbq/core/test_user/within.rb:
--------------------------------------------------------------------------------
1 | require 'active_support/core_ext/array/extract_options'
2 |
3 | module Bbq
4 | module Core
5 | class TestUser
6 | module Within
7 | METHODS_USING_WITHIN = [
8 | :see?, :not_see?,
9 | :attach_file, :check, :choose, :click_link_or_button, :click_button,
10 | :click_link, :click_on, :fill_in, :select, :uncheck, :unselect
11 | ]
12 |
13 | METHODS_USING_WITHIN.each do |method_name|
14 | class_eval <<-RUBY
15 | def #{method_name}(*args)
16 | using_within(args) { super }
17 | end
18 | RUBY
19 | end
20 |
21 | def using_within(args)
22 | options = args.extract_options!
23 | locator = options.delete(:within)
24 | args.push(options) unless options.empty?
25 |
26 | if locator
27 | within(locator) { yield }
28 | else
29 | yield
30 | end
31 | end
32 | end
33 | end
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/bbq-rails/bbq-rails.gemspec:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 | lib = File.expand_path('../lib', __FILE__)
3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4 | require 'bbq/rails/version'
5 |
6 | Gem::Specification.new do |spec|
7 | spec.name = "bbq-rails"
8 | spec.version = Bbq::Rails::VERSION
9 | spec.authors = ["DRUG - Dolnośląska Grupa Użytkowników Ruby"]
10 | spec.email = ["all@drug.org.pl"]
11 | spec.summary = %q{Rails integration for Bbq.}
12 | spec.description = spec.summary
13 | spec.homepage = ""
14 | spec.license = "MIT"
15 |
16 | spec.files = `git ls-files -z`.split("\x0")
17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19 | spec.require_paths = ["lib"]
20 |
21 | spec.add_dependency "bbq-core", "= 0.4.0"
22 |
23 | spec.add_development_dependency "rake"
24 | spec.add_development_dependency "rails", ">= 5.0"
25 | spec.add_development_dependency "minitest", "~> 5.0"
26 | end
27 |
--------------------------------------------------------------------------------
/bbq-rspec/spec/rspec_matchers_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'RSpec matchers' do
4 |
5 | specify 'see given string' do
6 | user = Bbq::Core::TestUser.new
7 | user.visit('/test_page')
8 |
9 | expect { expect(user).to see('Pink') }.to_not raise_error
10 | end
11 |
12 | specify 'unable to see given string' do
13 | user = Bbq::Core::TestUser.new
14 | user.visit('/test_page')
15 |
16 | expect { expect(user).to see('nothing to see') }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
17 | end
18 |
19 | specify 'see given string within scope' do
20 | user = Bbq::Core::TestUser.new
21 | user.visit('/test_page')
22 |
23 | expect { expect(user).to see('Pink').within('#unicorns') }.to_not raise_error
24 | end
25 |
26 | specify 'unable to see given string within scope' do
27 | user = Bbq::Core::TestUser.new
28 | user.visit('/test_page')
29 |
30 | expect { expect(user).to see('Violet').within('#unicorns') }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
31 | end
32 |
33 | end
34 |
--------------------------------------------------------------------------------
/bbq-core/bbq-core.gemspec:
--------------------------------------------------------------------------------
1 | # -*- encoding: utf-8 -*-
2 | $:.push File.expand_path("../lib", __FILE__)
3 | require "bbq/core/version"
4 |
5 | Gem::Specification.new do |s|
6 | s.name = "bbq-core"
7 | s.version = Bbq::Core::VERSION
8 | s.platform = Gem::Platform::RUBY
9 | s.authors = ["DRUG - Dolnośląska Grupa Użytkowników Ruby"]
10 | s.email = ["bbq@drug.org.pl"]
11 | s.homepage = ""
12 | s.description = %q{Objected oriented acceptance testing for Rails, using personas.}
13 | s.summary = %q{Objected oriented acceptance testing for Rails, using personas.}
14 |
15 | s.rubyforge_project = "bbq-core"
16 |
17 | s.files = `git ls-files`.split("\n")
18 | s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19 | s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20 | s.require_paths = ["lib"]
21 |
22 | s.add_dependency "capybara", ">= 2.0"
23 | s.add_dependency "activesupport", ">= 2.0"
24 |
25 | s.add_development_dependency "rake"
26 | s.add_development_dependency "minitest", "~> 5.0"
27 | end
28 |
--------------------------------------------------------------------------------
/bbq-devise/test/dummy/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the webserver when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Log error messages when you accidentally call methods on nil.
10 | config.whiny_nils = true
11 |
12 | # Show full error reports and disable caching
13 | config.consider_all_requests_local = true
14 | config.action_view.debug_rjs = true
15 | config.action_controller.perform_caching = false
16 |
17 | # Don't care if the mailer can't send
18 | config.action_mailer.raise_delivery_errors = false
19 |
20 | # Print deprecation notices to the Rails logger
21 | config.active_support.deprecation = :log
22 |
23 | # Only use best-standards-support built into browsers
24 | config.action_dispatch.best_standards_support = :builtin
25 | end
26 |
27 |
--------------------------------------------------------------------------------
/bbq-rails/test/bbq_install_generator_test.rb:
--------------------------------------------------------------------------------
1 | require "test_helper"
2 | require "rails/generators/test_case"
3 | require "generators/bbq/install_generator"
4 |
5 | class BbqInstallGeneratorTest < Rails::Generators::TestCase
6 | destination File.expand_path(File.join(File.dirname(__FILE__), '../tmp'))
7 | setup :prepare_destination
8 |
9 | tests Bbq::InstallGenerator
10 |
11 | def test_creating_test_unit_test_directories
12 | run_generator %w(-t test_unit)
13 |
14 | assert_directory "test/acceptance"
15 | assert_directory "test/support"
16 | end
17 |
18 | def test_creating_rspec_test_directories
19 | run_generator %w(-t rspec)
20 |
21 | assert_directory "spec/acceptance"
22 | assert_directory "spec/support"
23 | end
24 |
25 | def test_creating_test_unit_test_user_stub
26 | run_generator %w(-t test_unit)
27 |
28 | assert_file "test/support/test_user.rb", /class TestUser < Bbq::TestUser/
29 | end
30 |
31 | def test_creating_rspec_test_user_stub
32 | run_generator %w(-t rspec)
33 |
34 | assert_file "spec/support/test_user.rb", /class TestUser < Bbq::TestUser/
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/MIT-LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2011 DRUG, Dolnośląska Grupa Użytkowników Ruby
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/bbq-devise/bbq-devise.gemspec:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 | lib = File.expand_path('../lib', __FILE__)
3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4 | require 'bbq/devise/version'
5 |
6 | Gem::Specification.new do |spec|
7 | spec.name = "bbq-devise"
8 | spec.version = Bbq::Devise::VERSION
9 | spec.authors = ["Paweł Pacana"]
10 | spec.email = ["pawel.pacana@gmail.com"]
11 | spec.summary = %q{Devise integration for bbq.}
12 | spec.homepage = ""
13 | spec.license = "MIT"
14 |
15 | spec.files = `git ls-files -z`.split("\x0")
16 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18 | spec.require_paths = ["lib"]
19 |
20 | spec.add_dependency "bbq-core", "= 0.4.0"
21 | spec.add_dependency "bbq-rails", "= 0.4.0"
22 |
23 | spec.add_development_dependency "rake"
24 | spec.add_development_dependency "devise", ">= 4.0"
25 | spec.add_development_dependency "rails", ">= 5.0"
26 | spec.add_development_dependency "sqlite3", ">= 1.4"
27 | spec.add_development_dependency "minitest", "~> 5.0"
28 | end
29 |
--------------------------------------------------------------------------------
/bbq/bbq.gemspec:
--------------------------------------------------------------------------------
1 | # -*- encoding: utf-8 -*-
2 | $:.push File.expand_path("../lib", __FILE__)
3 | require "bbq/version"
4 |
5 | Gem::Specification.new do |s|
6 | s.name = "bbq"
7 | s.version = Bbq::VERSION
8 | s.platform = Gem::Platform::RUBY
9 | s.authors = ["DRUG - Dolnośląska Grupa Użytkowników Ruby"]
10 | s.email = ["bbq@drug.org.pl"]
11 | s.homepage = ""
12 | s.description = %q{Objected oriented acceptance testing for Rails, using personas.}
13 | s.summary = %q{Objected oriented acceptance testing for Rails, using personas.}
14 |
15 | s.rubyforge_project = "bbq"
16 |
17 | s.files = `git ls-files`.split("\n")
18 | s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19 | s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20 | s.require_paths = ["lib"]
21 |
22 | s.add_dependency "bbq-core" , "= 0.4.0"
23 | s.add_dependency "bbq-rspec", "= 0.4.0"
24 | s.add_dependency "bbq-rails", "= 0.4.0"
25 | s.add_dependency "bbq-devise", "= 0.4.0"
26 | s.add_dependency "activesupport", ">= 2.0"
27 |
28 | s.add_development_dependency "rake"
29 | s.add_development_dependency "minitest", "~> 5.0"
30 | end
31 |
--------------------------------------------------------------------------------
/bbq-rspec/lib/bbq/rspec.rb:
--------------------------------------------------------------------------------
1 | require "bbq/core"
2 | require "bbq/core/test_user"
3 | require "bbq/rspec/version"
4 | require "bbq/rspec/matchers"
5 | require "rspec/core"
6 | require "capybara/rspec/matchers"
7 |
8 | module Bbq
9 | module RSpec
10 | module Feature
11 | def self.included(base)
12 | base.metadata[:type] = :acceptance
13 | base.metadata[:caller] = caller
14 |
15 | base.instance_eval do
16 | alias :background :before
17 | alias :scenario :it
18 | alias :feature :describe
19 | end
20 | end
21 | end
22 |
23 | ::RSpec.configure do |config|
24 | if Gem::Version.new(::RSpec::Core::Version::STRING) >= Gem::Version.new('2.99')
25 | config.include Feature, :type => :acceptance, :file_path => %r{spec/acceptance}
26 | else
27 | config.include Feature, :type => :acceptance, :example_group => {:file_path => %r{spec/acceptance}}
28 | end
29 | config.include Matchers
30 | config.after :each, :type => :acceptance do
31 | ::Bbq::Core::Session.pool.release
32 | end
33 | end
34 | end
35 |
36 | module Core
37 | class TestUser
38 | include Capybara::RSpecMatchers
39 | include ::Bbq::RSpec::Matchers
40 | include ::RSpec::Matchers
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/bbq-core/test/session_pool_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 | require 'bbq/core/test_user'
3 |
4 | class SessionPoolTest < Minitest::Test
5 |
6 | def setup
7 | Bbq::Core::Session.instance_variable_set(:@pool, nil)
8 | end
9 |
10 | def test_reuses_sessions
11 | pool = Bbq::Core::Session::Pool.new
12 | user1 = Bbq::Core::TestUser.new(:pool => pool).tap { |u| u.page }
13 | pool.release
14 | user2 = Bbq::Core::TestUser.new(:pool => pool).tap { |u| u.page }
15 |
16 | assert_same user1.page, user2.page
17 | end
18 |
19 | def test_has_default_pool
20 | user1 = Bbq::Core::TestUser.new.tap { |u| u.page }
21 | Bbq::Core::Session::pool.release
22 | user2 = Bbq::Core::TestUser.new.tap { |u| u.page }
23 |
24 | assert_same user1.page, user2.page
25 | end
26 |
27 | def test_without_pool
28 | user1 = Bbq::Core::TestUser.new(:pool => false).tap { |u| u.page }
29 | Bbq::Core::Session::pool.release
30 | user2 = Bbq::Core::TestUser.new(:pool => false).tap { |u| u.page }
31 |
32 | refute_same user1.page, user2.page
33 | end
34 |
35 | def test_pool_returns_correct_driver
36 | pool = Bbq::Core::Session::Pool.new
37 | pool.next(:rack_test)
38 | pool.next(:rack_test_the_other)
39 | pool.release
40 |
41 | assert_equal :rack_test, pool.next(:rack_test).mode
42 | end
43 |
44 | end
45 |
--------------------------------------------------------------------------------
/bbq-core/lib/bbq/core/session.rb:
--------------------------------------------------------------------------------
1 | require 'bbq/core'
2 |
3 | module Bbq
4 | module Core
5 | module Session
6 | extend self
7 |
8 | def next(options = {})
9 | driver = options.delete(:driver)
10 | pool = options.delete(:pool)
11 |
12 | if pool
13 | pool.next(driver)
14 | else
15 | create(driver)
16 | end
17 | end
18 |
19 | def create(driver)
20 | Capybara::Session.new(driver, Bbq::Core.app)
21 | end
22 |
23 | def pool
24 | @pool ||= Pool.new
25 | end
26 |
27 | class Pool
28 | attr_accessor :idle, :taken
29 |
30 | def initialize
31 | @idle = []
32 | @taken = []
33 | end
34 |
35 | def next(driver)
36 | take_idle(driver) || create(driver)
37 | end
38 |
39 | def release
40 | taken.each(&:reset!)
41 | idle.concat(taken)
42 | taken.clear
43 | end
44 |
45 | private
46 |
47 | def take_idle(driver)
48 | idle.find { |s| s.mode == driver }.tap do |session|
49 | if session
50 | idle.delete(session)
51 | taken.push(session)
52 | end
53 | end
54 | end
55 |
56 | def create(driver)
57 | Bbq::Core::Session.create(driver).tap do |session|
58 | taken.push(session)
59 | end
60 | end
61 | end
62 | end
63 | end
64 | end
65 |
--------------------------------------------------------------------------------
/bbq/CHANGELOG:
--------------------------------------------------------------------------------
1 | 0.2.1 / 2013-08-22
2 | ==================
3 |
4 | * bugfix: Bbq::TestClient propagates NoMethodErrors from the controller of
5 | tested app instead of rising unsupported method errors.
6 |
7 | 0.2.0 / 2013-01-06
8 | ==================
9 |
10 | * Dropped support for Ruby 1.8.7
11 | * Capybara 2.0 support
12 |
13 | 0.1.0 / 2013-01-06
14 | ==================
15 |
16 | * Extracted Rails' URL helpers inclusion to separate module
17 | * Include only Capybara::Session::DSL_METHODS in TestUser, not the whole Capybara::DSL
18 | * Added Capybara sessions pool
19 | * Moved Test::User default options to separate method
20 | * Added Test::Client for testing REST APIs
21 | * Renamed bbq/test.rb to bbq/test_unit.rb. You may want to fix your test_helper.
22 | * Moved require bbq/test_user to generated test_user.rb. You may want to update your existing test_user.rb.
23 | * Fixed Capybara 'within' scope for RSpec flavour
24 |
25 | 0.0.4 / 2011-10-19
26 | ==================
27 |
28 | * Make Bbq work with Capybara 1.0 and 1.1
29 | * Rails is development dependency
30 |
31 | 0.0.3 / 2011-07-14
32 | ==================
33 |
34 | * Added support and tests for Sinatra
35 | * Added Bbq.app and Bbq.app=
36 |
37 | 0.0.2 / 2011-07-01
38 | ==================
39 |
40 | * Extracted Bbq::TestUser::Eyes module
41 | * Added :within option to TestUser methods
42 | * Fix tests for ree and ruby187
43 |
44 | 0.0.1 / 2011-04-20
45 | ==================
46 |
47 | * Bbq introduced to the wild world!
48 |
--------------------------------------------------------------------------------
/bbq-core/CHANGELOG:
--------------------------------------------------------------------------------
1 | 0.2.1 / 2013-08-22
2 | ==================
3 |
4 | * bugfix: Bbq::TestClient propagates NoMethodErrors from the controller of
5 | tested app instead of rising unsupported method errors.
6 |
7 | 0.2.0 / 2013-01-06
8 | ==================
9 |
10 | * Dropped support for Ruby 1.8.7
11 | * Capybara 2.0 support
12 |
13 | 0.1.0 / 2013-01-06
14 | ==================
15 |
16 | * Extracted Rails' URL helpers inclusion to separate module
17 | * Include only Capybara::Session::DSL_METHODS in TestUser, not the whole Capybara::DSL
18 | * Added Capybara sessions pool
19 | * Moved Test::User default options to separate method
20 | * Added Test::Client for testing REST APIs
21 | * Renamed bbq/test.rb to bbq/test_unit.rb. You may want to fix your test_helper.
22 | * Moved require bbq/test_user to generated test_user.rb. You may want to update your existing test_user.rb.
23 | * Fixed Capybara 'within' scope for RSpec flavour
24 |
25 | 0.0.4 / 2011-10-19
26 | ==================
27 |
28 | * Make Bbq work with Capybara 1.0 and 1.1
29 | * Rails is development dependency
30 |
31 | 0.0.3 / 2011-07-14
32 | ==================
33 |
34 | * Added support and tests for Sinatra
35 | * Added Bbq.app and Bbq.app=
36 |
37 | 0.0.2 / 2011-07-01
38 | ==================
39 |
40 | * Extracted Bbq::TestUser::Eyes module
41 | * Added :within option to TestUser methods
42 | * Fix tests for ree and ruby187
43 |
44 | 0.0.1 / 2011-04-20
45 | ==================
46 |
47 | * Bbq introduced to the wild world!
48 |
--------------------------------------------------------------------------------
/bbq-devise/test/dummy/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Log error messages when you accidentally call methods on nil.
11 | config.whiny_nils = true
12 |
13 | # Show full error reports and disable caching
14 | config.consider_all_requests_local = true
15 | config.action_controller.perform_caching = false
16 |
17 | # Raise exceptions instead of rendering exception templates
18 | config.action_dispatch.show_exceptions = false
19 |
20 | # Disable request forgery protection in test environment
21 | config.action_controller.allow_forgery_protection = false
22 |
23 | # Tell Action Mailer not to deliver emails to the real world.
24 | # The :test delivery method accumulates sent emails in the
25 | # ActionMailer::Base.deliveries array.
26 | config.action_mailer.delivery_method = :test
27 |
28 | # Use SQL instead of Active Record's schema dumper when creating the test database.
29 | # This is necessary if your schema can't be completely dumped by the schema dumper,
30 | # like if you have constraints or database-specific column types
31 | # config.active_record.schema_format = :sql
32 |
33 | # Print deprecation notices to the stderr
34 | config.active_support.deprecation = :stderr
35 | end
36 |
--------------------------------------------------------------------------------
/bbq-devise/lib/bbq/devise.rb:
--------------------------------------------------------------------------------
1 | require "bbq/devise/version"
2 | require "securerandom"
3 |
4 | module Bbq
5 | module Devise
6 | attr_accessor :devise_authentication_key, :email, :password, :scope
7 |
8 | def self.included(klass)
9 | require 'bbq/rails/routes'
10 | klass.send(:include, Bbq::Rails::Routes)
11 | end
12 |
13 | def initialize_devise
14 | @devise_initialized ||= begin
15 | self.devise_authentication_key = ::Devise.authentication_keys.first
16 | self.email = options[devise_authentication_key.to_sym] || Bbq::Devise.next_email
17 | self.password = options[:password] || Bbq::Devise.next_password
18 | self.scope = ::Devise.mappings.first.second.singular.to_s
19 | true
20 | end
21 | end
22 |
23 | def register
24 | initialize_devise
25 | visit send("new_#{scope}_registration_path")
26 | fill_in "#{scope}_#{devise_authentication_key}", :with => @email
27 | fill_in "#{scope}_password", :with => @password
28 | fill_in "#{scope}_password_confirmation", :with => @password
29 | find(:xpath, "//input[@name='commit']").click
30 | end
31 |
32 | def login
33 | initialize_devise
34 | visit send("new_#{scope}_session_path")
35 | fill_in "#{scope}_#{devise_authentication_key}", :with => @email
36 | fill_in "#{scope}_password", :with => @password
37 | find(:xpath, "//input[@name='commit']").click
38 | end
39 |
40 | def logout
41 | visit send("destroy_#{scope}_session_path")
42 | end
43 |
44 | def register_and_login
45 | register
46 | end
47 |
48 | def self.next_email
49 | "#{SecureRandom.hex(3)}@example.com"
50 | end
51 |
52 | def self.next_password
53 | SecureRandom.hex(8)
54 | end
55 | end
56 | end
57 |
--------------------------------------------------------------------------------
/bbq-rspec/lib/bbq/rspec/matchers/see.rb:
--------------------------------------------------------------------------------
1 | module Bbq
2 | module RSpec
3 | module Matchers
4 | module See
5 | class Matcher
6 | attr_reader :text, :scope
7 |
8 | def initialize(text)
9 | @text = text
10 | @scope = nil
11 | end
12 |
13 | def description
14 | if scope
15 | "see #{text} within #{scope}"
16 | else
17 | "see #{text}"
18 | end
19 | end
20 |
21 | def matches?(actor)
22 | @actual = page_fragment(actor)
23 | @actual.has_text?(text)
24 | end
25 |
26 | def does_not_match?(actor)
27 | @actual = page_fragment(actor)
28 | @actual.has_no_text?(text)
29 | end
30 |
31 | def failure_message_for_should
32 | "expected to see \"#{text}\" in #{format(@actual.text)}"
33 | end
34 | alias :failure_message :failure_message_for_should
35 |
36 | def failure_message_for_should_not
37 | "expected not to see \"#{text}\" in #{format(@actual.text)}"
38 | end
39 | alias :failure_message_when_negated :failure_message_for_should_not
40 |
41 | def within(scope)
42 | @scope = scope
43 | self
44 | end
45 |
46 | private
47 | def page_fragment(actor)
48 | if scope
49 | actor.page.first(*scope)
50 | else
51 | actor.page
52 | end
53 | end
54 |
55 | def format(text)
56 | case text
57 | when Regexp
58 | text.inspect
59 | else
60 | text.to_s.gsub(/[[:space:]]+/, ' ').strip.inspect
61 | end
62 | end
63 | end
64 |
65 | def see(text)
66 | Matcher.new(text)
67 | end
68 | end
69 | end
70 | end
71 | end
72 |
--------------------------------------------------------------------------------
/bbq-devise/test/dummy/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # The production environment is meant for finished, "live" apps.
5 | # Code is not reloaded between requests
6 | config.cache_classes = true
7 |
8 | # Full error reports are disabled and caching is turned on
9 | config.consider_all_requests_local = false
10 | config.action_controller.perform_caching = true
11 |
12 | # Specifies the header that your server uses for sending files
13 | config.action_dispatch.x_sendfile_header = "X-Sendfile"
14 |
15 | # For nginx:
16 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17 |
18 | # If you have no front-end server that supports something like X-Sendfile,
19 | # just comment this out and Rails will serve the files
20 |
21 | # See everything in the log (default is :info)
22 | # config.log_level = :debug
23 |
24 | # Use a different logger for distributed setups
25 | # config.logger = SyslogLogger.new
26 |
27 | # Use a different cache store in production
28 | # config.cache_store = :mem_cache_store
29 |
30 | # Disable Rails's static asset server
31 | # In production, Apache or nginx will already do this
32 | config.serve_static_assets = false
33 |
34 | # Enable serving of images, stylesheets, and javascripts from an asset server
35 | # config.action_controller.asset_host = "http://assets.example.com"
36 |
37 | # Disable delivery errors, bad email addresses will be ignored
38 | # config.action_mailer.raise_delivery_errors = false
39 |
40 | # Enable threaded mode
41 | # config.threadsafe!
42 |
43 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44 | # the I18n.default_locale when a translation can not be found)
45 | config.i18n.fallbacks = true
46 |
47 | # Send deprecation notices to registered listeners
48 | config.active_support.deprecation = :notify
49 | end
50 |
--------------------------------------------------------------------------------
/bbq-rails/README.md:
--------------------------------------------------------------------------------
1 | # Bbq::Rails
2 |
3 | [](http://travis-ci.org/drugpl/bbq-rails) [](https://gemnasium.com/drugpl/bbq-rails) [](https://codeclimate.com/github/drugpl/bbq-rails) [](http://badge.fury.io/rb/bbq-rails)
4 |
5 | ## Quick start
6 |
7 | Add following to your Gemfile:
8 |
9 | ```ruby
10 | gem 'bbq-rails', require: 'bbq/rails'
11 |
12 | ```
13 |
14 | You may also run `rails generate bbq:install` to have a basic configuration generated.
15 |
16 | ## Features
17 |
18 | ### Test integration
19 |
20 | Your Rails application hooks up to `Bbq::Core.app` in tests automatically. Thus `Bbq::Core::TestUser` and `Bbq::Core::TestClient` can run against it.
21 |
22 | ### Generators
23 |
24 | Generators help you kickstart Bbq test environment.
25 |
26 | At the beginning of your journey with Bbq you can use `rails generate bbq:install`. It'll create directory for acceptance test files and give you basic TestUser class for customization.
27 |
28 | There's also `rails generate bbq:test` which creates new test files for you which have Bbq goodies baked in (DSL and test actor session pool handling).
29 |
30 | ### Rake integration
31 |
32 | Provided you've created `spec/acceptance` or `test/acceptance` directory, there we'll be following tasks for running acceptance tests available: `bundle exec rake spec:acceptance` or `bundle exec rake test:acceptance` respectively.
33 |
34 | ### Routes
35 |
36 | When you require 'bbq/rails/routes' you can then `include Bbq::Rails::Routes` in TestActor to have access to Rails url helpers. While convenient it's not recommended in general. Testing routes is part of acceptance test. Use links and buttons in order to get to other pages in your app.
37 |
38 | ```ruby
39 | require 'bbq/rails/routes'
40 |
41 | class TestUser < Bbq::TestUser
42 | include Bbq::Rails::Routes
43 | end
44 | ```
45 |
46 | ## Development
47 |
48 | We develop and test against multiple Rails versions. When working with legacy software a test toolkit should be the last to require special attention.
49 |
50 | ```sh
51 | for gemfile in `ls Gemfile* | grep -v lock`; do
52 | BUNDLE_GEMFILE=$gemfile bundle install
53 | BUNDLE_GEMFILE=$gemfile bundle exec rake test
54 | done
55 |
--------------------------------------------------------------------------------
/bbq-core/lib/bbq/core/test_client.rb:
--------------------------------------------------------------------------------
1 | require 'bbq/core/roles'
2 |
3 | module Bbq
4 | module Core
5 | class TestClient
6 | class UnsupportedMethodError < StandardError; end
7 |
8 | include Bbq::Core::Roles
9 |
10 | def initialize(options = {})
11 | @options = options
12 | end
13 |
14 | HTTP_METHODS = %w(get post put delete head options patch)
15 |
16 | HTTP_METHODS.each do |method|
17 | class_eval <<-RUBY
18 | def #{method}(path, params = {}, headers = {})
19 | unless driver.respond_to? :#{method}
20 | raise UnsupportedMethodError, "Your driver does not support #{method.upcase} method"
21 | end
22 |
23 | response = driver.#{method}(path, params, default_headers.merge(headers))
24 | parsed_response = parse_response(response)
25 | yield parsed_response if block_given?
26 | parsed_response
27 | end
28 | RUBY
29 | end
30 |
31 | protected
32 | def app
33 | @options[:app] || Bbq::Core.app
34 | end
35 |
36 | def default_headers
37 | @options[:headers] || {}
38 | end
39 |
40 | def driver
41 | @driver ||= RackTest.new(app)
42 | end
43 |
44 | def parse_response(response)
45 | case response.headers["Content-Type"]
46 | when /^application\/(.*\+)?json/
47 | response.extend(JsonBody)
48 | when /^application\/(.*\+)?x-yaml/
49 | response.extend(YamlBody)
50 | else
51 | response
52 | end
53 | end
54 |
55 | class RackTest
56 | attr_accessor :app
57 |
58 | def initialize(app)
59 | self.app = app
60 | end
61 |
62 | module ConvertHeaders
63 | HTTP_METHODS.each do |method|
64 | class_eval <<-RUBY
65 | def #{method}(path, params = {}, headers = {})
66 | super(path, params, to_env_headers(headers))
67 | end
68 | RUBY
69 | end
70 |
71 | def to_env_headers(http_headers)
72 | http_headers.map do |k, v|
73 | k = k.upcase.gsub("-", "_")
74 | k = "HTTP_#{k}" unless ["CONTENT_TYPE", "CONTENT_LENGTH"].include?(k)
75 | { k => v }
76 | end.inject({}, :merge)
77 | end
78 | end
79 |
80 | include Rack::Test::Methods
81 | include ConvertHeaders
82 | end
83 |
84 | module JsonBody
85 | def body
86 | @parsed_body ||= super.empty?? super : JSON.parse(super)
87 | end
88 | end
89 |
90 | module YamlBody
91 | def body
92 | @parsed_body ||= YAML.load(super)
93 | end
94 | end
95 | end
96 | end
97 | end
98 |
--------------------------------------------------------------------------------
/bbq-rspec/README.md:
--------------------------------------------------------------------------------
1 | # Bbq-rspec
2 |
3 | [](http://travis-ci.org/drugpl/bbq-rspec) [](https://gemnasium.com/drugpl/bbq-rspec) [](https://codeclimate.com/github/drugpl/bbq-rspec) [](http://badge.fury.io/rb/bbq-rspec)
4 |
5 |
6 | RSpec integration for object oriented acceptance testing with [bbq](https://github.com/drugpl/bbq).
7 |
8 | ## Setup
9 |
10 | Add `bbq-rspec` to your `Gemfile`:
11 |
12 | ```ruby
13 | gem "bbq-rspec"
14 | ```
15 |
16 | Run install generator:
17 |
18 | ```
19 | bundle exec rails generate bbq:install
20 | ```
21 |
22 | Require BBQ in spec/spec_helper.rb:
23 |
24 | ```ruby
25 | require "bbq/rspec"
26 | ```
27 |
28 | ## Feature generator
29 |
30 | ```
31 | bundle exec rails g bbq:test MyFeatureName
32 | ```
33 |
34 | ## Running features
35 |
36 | ```
37 | bundle exec rake spec:acceptance
38 | ```
39 |
40 | ## Examples
41 |
42 | ```ruby
43 | class TestUser < Bbq::TestUser
44 | def email
45 | @options[:email] || "buyer@example.com"
46 | end
47 |
48 | module Buyer
49 | def ask_question(question)
50 | fill_in "question", :with => question
51 | fill_in "email", :with => email
52 | click_on("Ask")
53 | end
54 |
55 | def go_to_page_and_open_widget(page_url, &block)
56 | go_to_page(page_url)
57 | open_widget &block
58 | end
59 |
60 | def go_to_page(page_url)
61 | visit page_url
62 | wait_until { page.find("iframe") }
63 | end
64 |
65 | def open_widget
66 | within_widget do
67 | page.find("#widget h3").click
68 | yield if block_given?
69 | end
70 | end
71 |
72 | def within_widget(&block)
73 | within_frame(widget_frame, &block)
74 | end
75 |
76 | def widget_frame
77 | page.evaluate_script("document.getElementsByTagName('iframe')[0].id")
78 | end
79 | end
80 | end
81 | ```
82 |
83 | ```ruby
84 | feature "ask question widget" do
85 | let(:user) {
86 | user = TestUser.new(:driver => :webkit)
87 | user.roles('buyer')
88 | user
89 | }
90 |
91 | scenario "as a guest user, I should be able to ask a question" do
92 | user.go_to_page_and_open_widget("/widget") do
93 | user.ask_question "my question"
94 | expect(user).to see("Thanks!")
95 | end
96 | end
97 | end
98 | ```
99 |
100 | ## Contributing
101 |
102 | 1. Fork it ( https://github.com/drugpl/bbq-rspec/fork )
103 | 2. Create your feature branch (`git checkout -b my-new-feature`)
104 | 3. Commit your changes (`git commit -am 'Add some feature'`)
105 | 4. Push to the branch (`git push origin my-new-feature`)
106 | 5. Create a new Pull Request
107 |
--------------------------------------------------------------------------------
/bbq-core/test/test_user_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 | require 'bbq/core/test_user'
3 |
4 |
5 | def text(output)
6 | end
7 |
8 | def html(output)
9 | ->{ ['200', {'Content-Type' => 'text/html'}, [output]] }
10 | end
11 |
12 | TestApp = Rack::Builder.new do
13 | map '/' do
14 | run ->(env) { ['200', {'Content-Type' => 'text/plain'}, ['BBQ']] }
15 | end
16 |
17 | map '/miracle' do
18 | run ->(env) { ['200', {'Content-Type' => 'text/plain'}, ['MIRACLE']] }
19 | end
20 |
21 | map '/ponycorns' do
22 | run ->(env) { ['200', {'Content-Type' => 'text/html'}, [<
24 |
Pink
25 |
26 |
27 |
Violet
28 |
29 |
30 |
31 |
32 | More ponycorns
33 | HTML
34 | ]] }
35 | end
36 | end
37 |
38 |
39 | class TestUser < Bbq::Core::TestUser
40 | module Commenter
41 | def comment
42 | end
43 | end
44 |
45 | module VideoUploader
46 | def upload
47 | end
48 | end
49 |
50 | module CommentModerator
51 | def moderate
52 | end
53 | end
54 | end
55 |
56 | class TestUserTest < Minitest::Test
57 |
58 | def setup
59 | Bbq::Core.app = TestApp
60 | end
61 |
62 | def teardown
63 | Bbq::Core.app = nil
64 | end
65 |
66 | def test_capybara_dsl_methods
67 | user = TestUser.new
68 | Capybara::Session::DSL_METHODS.each do |m|
69 | assert user.respond_to?(m)
70 | end
71 | end
72 |
73 | def test_driver_option
74 | user = TestUser.new(:driver => :rack_test_the_other)
75 | assert_equal :rack_test_the_other, user.page.mode
76 | end
77 |
78 | def test_roles
79 | user = TestUser.new
80 | %w(comment upload moderate).each { |m| assert !user.respond_to?(m) }
81 |
82 | user.roles(:commenter, "comment_moderator")
83 | %w(comment moderate).each { |m| assert user.respond_to?(m) }
84 | assert !user.respond_to?(:upload)
85 |
86 | user.roles(:video_uploader)
87 | %w(comment upload moderate).each { |m| assert user.respond_to?(m) }
88 | end
89 |
90 | def test_explicit_user_eyes
91 | @user = TestUser.new
92 | @user.visit "/miracle"
93 | assert @user.not_see?("BBQ")
94 | assert @user.see?("MIRACLE")
95 | end
96 |
97 | def test_user_eyes_within_scope
98 | @user = TestUser.new
99 | @user.visit "/ponycorns"
100 | assert @user.see?("Pink", :within => "#unicorns")
101 | assert ! @user.see?("Violet", :within => "#unicorns")
102 | assert @user.not_see?("Violet", :within => "#unicorns")
103 | assert ! @user.not_see?("Pink", :within => "#unicorns")
104 |
105 | @user.fill_in "color", :with => "red", :within => "#new_pony"
106 | assert_raises Capybara::ElementNotFound do
107 | @user.fill_in "color", :with => "red", :within => "#new_unicorn"
108 | end
109 | @user.click_link "More ponycorns"
110 | end
111 |
112 | end
113 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | UPSTREAM_REV = `git rev-parse upstream/master`
2 | ORIGIN_REV = `git rev-parse origin/master`
3 | CURRENT_REV = `git rev-parse HEAD`
4 | BBQ_VERSION ?= $(shell cat BBQ_VERSION)
5 | NIX_TYPE = $(shell uname -s)
6 | GEMS = bbq \
7 | bbq-core \
8 | bbq-rspec \
9 | bbq-rails \
10 | bbq-devise
11 |
12 | ifeq ($(NIX_TYPE),Linux)
13 | SED_OPTS = -i
14 | endif
15 |
16 | ifeq ($(NIX_TYPE),Darwin)
17 | SED_OPTS = -i ""
18 | endif
19 |
20 | $(addprefix install-, $(GEMS)):
21 | @make -C $(subst install-,,$@) install
22 |
23 | $(addprefix reinstall-, $(GEMS)):
24 | @make -C $(subst reinstall-,,$@) reinstall
25 |
26 | $(addprefix test-, $(GEMS)):
27 | @make -C $(subst test-,,$@) test
28 |
29 | $(addprefix build-, $(GEMS)):
30 | @make -C $(subst build-,,$@) build
31 |
32 | $(addprefix push-, $(GEMS)):
33 | @make -C $(subst push-,,$@) push
34 |
35 | $(addprefix clean-, $(GEMS)):
36 | @make -C $(subst clean-,,$@) clean
37 |
38 | git-check-clean:
39 | @git diff --quiet --exit-code
40 |
41 | git-check-committed:
42 | @git diff-index --quiet --cached HEAD
43 |
44 | git-tag:
45 | @git tag -m "Version v$(BBQ_VERSION)" v$(BBQ_VERSION)
46 | @git push origin master --tags
47 |
48 | git-rebase-from-upstream:
49 | @git remote remove upstream > /dev/null 2>&1 || true
50 | @git remote add upstream git@github.com:RailsEventStore/rails_event_store.git
51 | @git fetch upstream master
52 | @git rebase upstream/master
53 | @git push origin master
54 |
55 | set-version: git-check-clean git-check-committed
56 | @echo $(BBQ_VERSION) > BBQ_VERSION
57 | @find . -path ./contrib -prune -o -name version.rb -exec sed $(SED_OPTS) "s/\(VERSION = \)\(.*\)/\1\"$(BBQ_VERSION)\"/" {} \;
58 | @find . -path ./contrib -prune -o -name *.gemspec -exec sed $(SED_OPTS) "s/\(\"bbq-core\", \)\(.*\)/\1\"= $(BBQ_VERSION)\"/" {} \;
59 | @find . -path ./contrib -prune -o -name *.gemspec -exec sed $(SED_OPTS) "s/\(\"bbq-rspec\", \)\(.*\)/\1\"= $(BBQ_VERSION)\"/" {} \;
60 | @find . -path ./contrib -prune -o -name *.gemspec -exec sed $(SED_OPTS) "s/\(\"bbq-rails\", \)\(.*\)/\1\"= $(BBQ_VERSION)\"/" {} \;
61 | @find . -path ./contrib -prune -o -name *.gemspec -exec sed $(SED_OPTS) "s/\(\"bbq-devise\", \)\(.*\)/\1\"= $(BBQ_VERSION)\"/" {} \;
62 | @git add -A **/*.gemspec **/version.rb BBQ_VERSION
63 | @git commit -m "Version v$(BBQ_VERSION)"
64 |
65 | install: $(addprefix install-, $(GEMS)) ## Install all dependencies
66 |
67 | reinstall: $(addprefix reinstall-, $(GEMS)) ## Reinstall (with new resolve) dependencies
68 |
69 | test: $(addprefix test-, $(GEMS)) ## Run all unit tests
70 |
71 | build: $(addprefix build-, $(GEMS)) ## Build all gem packages
72 |
73 | push: $(addprefix push-, $(GEMS)) ## Push all gem packages to RubyGems
74 |
75 | clean: $(addprefix clean-, $(GEMS)) ## Remove all previously built packages
76 |
77 | release: git-check-clean git-check-committed install test git-tag clean build push ## Make a new release on RubyGems
78 | @echo Released v$(BBQ_VERSION)
79 |
80 | include support/make/help.mk
81 |
--------------------------------------------------------------------------------
/bbq/README.md:
--------------------------------------------------------------------------------
1 | # BBQ
2 |
3 | [](http://travis-ci.org/drugpl/bbq) [](https://gemnasium.com/drugpl/bbq) [](https://codeclimate.com/github/drugpl/bbq) [](http://badge.fury.io/rb/bbq)
4 |
5 | Object oriented acceptance testing using personas.
6 |
7 | * Ruby (no Gherkin)
8 | * Objects and methods instead of steps
9 | * Test framework independent (RSpec and Test::Unit support)
10 | * Thins based on Capybara.
11 | * DCI (Data Context Interaction) for roles/personas
12 | * Opinionated
13 |
14 | ## Setup
15 |
16 | First, add BBQ to your apps `Gemfile`:
17 |
18 | ```ruby
19 | gem "bbq", "0.2.1"
20 | ```
21 |
22 | Run install generator:
23 |
24 | ```
25 | bundle exec rails generate bbq:install
26 | ```
27 |
28 | Require BBQ in test/test_helper.rb (in case of Test::Unit):
29 |
30 | ```ruby
31 | require "bbq/test_unit"
32 | ```
33 |
34 | Require BBQ in spec/spec_helper.rb (in case of RSpec):
35 |
36 | ```ruby
37 | require "bbq/rspec"
38 | ```
39 |
40 | ## Feature generator
41 |
42 | ```
43 | bundle exec rails g bbq:test MyFeatureName
44 | ```
45 |
46 | ## Running features
47 |
48 | For Test::Unit flavour:
49 |
50 | ```
51 | bundle exec rake test:acceptance
52 | ```
53 |
54 | For RSpec flavour:
55 |
56 | ```
57 | bundle exec rake spec:acceptance
58 | ```
59 |
60 | ## Examples
61 |
62 | ### Roles and Devise integration
63 |
64 | ```ruby
65 | class TestUser < Bbq::TestUser
66 | include Bbq::Devise
67 |
68 | def update_ticket(summary, comment)
69 | show_ticket(summary)
70 | fill_in "Comment", :with => comment
71 | click_on "Add update"
72 | end
73 |
74 | def open_application
75 | visit '/'
76 | end
77 |
78 | module TicketReporter
79 | def open_tickets_listing
80 | open_application
81 | click_link 'Tickets'
82 | end
83 |
84 | def open_ticket(summary, description)
85 | open_tickets_listing
86 | click_on "Open a new ticket"
87 | fill_in "Summary", :with => summary
88 | fill_in "Description", :with => description
89 | click_on "Open ticket"
90 | end
91 |
92 | def show_ticket(summary)
93 | open_tickets_listing
94 | click_on summary
95 | end
96 | end
97 |
98 | module TicketManager
99 | def open_administration
100 | visit '/admin'
101 | end
102 |
103 | def open_tickets_listing
104 | open_administration
105 | click_link 'Tickets'
106 | end
107 |
108 | def close_ticket(summary, comment = nil)
109 | open_tickets_listing
110 | click_on summary
111 | fill_in "Comment", :with => comment if comment
112 | click_on "Close ticket"
113 | end
114 |
115 | def show_ticket(summary)
116 | open_tickets_listing
117 | click_on summary
118 | end
119 | end
120 | end
121 | ```
122 |
123 | ```ruby
124 | class AdminTicketsTest < Bbq::TestCase
125 | background do
126 | admin = Factory(:admin)
127 | @email, @password = admin.email, admin.password
128 | end
129 |
130 | scenario "admin can browse all user tickets" do
131 | summaries = ["Forgot my password", "Page is not displayed correctly"]
132 | descriptions = ["I lost my yellow note with password under the table!",
133 | "My IE renders crap instead of crispy fonts!"]
134 |
135 | alice = TestUser.new
136 | alice.roles(:ticket_reporter)
137 | alice.register_and_login
138 | alice.open_ticket(summaries.first, descriptions.first)
139 |
140 | bob = TestUser.new
141 | bob.roles(:ticket_reporter)
142 | bob.register_and_login
143 | bob.open_ticket(summaries.second, descriptions.second)
144 |
145 | charlie = TestUser.new(:email => @email, :password => @password)
146 | charlie.login # charlie was already "registered" in factory as admin
147 | charlie.roles(:ticket_manager)
148 | charlie.open_tickets_listing
149 | charlie.see!(*summaries)
150 |
151 | charlie.click_on(summaries.second)
152 | charlie.see!(summaries.second, descriptions.second)
153 | charlie.not_see!(summaries.first, descriptions.first)
154 | end
155 | end
156 | ```
157 |
158 | ### RSpec integration
159 |
160 | ```ruby
161 | class TestUser < Bbq::TestUser
162 | def email
163 | @options[:email] || "buyer@example.com"
164 | end
165 |
166 | module Buyer
167 | def ask_question(question)
168 | fill_in "question", :with => question
169 | fill_in "email", :with => email
170 | click_on("Ask")
171 | end
172 |
173 | def go_to_page_and_open_widget(page_url, &block)
174 | go_to_page(page_url)
175 | open_widget &block
176 | end
177 |
178 | def go_to_page(page_url)
179 | visit page_url
180 | wait_until { page.find("iframe") }
181 | end
182 |
183 | def open_widget
184 | within_widget do
185 | page.find("#widget h3").click
186 | yield if block_given?
187 | end
188 | end
189 |
190 | ef within_widget(&block)
191 | within_frame(widget_frame, &block)
192 | end
193 |
194 | def widget_frame
195 | page.evaluate_script("document.getElementsByTagName('iframe')[0].id")
196 | end
197 | end
198 | end
199 | ```
200 |
201 | ```ruby
202 | feature "ask question widget" do
203 | let(:user) {
204 | user = TestUser.new(:driver => :webkit)
205 | user.roles('buyer')
206 | user
207 | }
208 |
209 | scenario "as a guest user, I should be able to ask a question" do
210 | user.go_to_page_and_open_widget("/widget") do
211 | user.ask_question "my question"
212 | user.see!("Thanks!")
213 | end
214 | end
215 | end
216 | ```
217 |
218 | ## Testing REST APIs
219 |
220 | Bbq provides `Bbq::TestClient`, similar to `Bbq::TestUser`, but intended for testing APIs.
221 | It's a thin wrapper around `Rack::Test` which allows you to send requests and run assertions
222 | against responses.
223 |
224 | ```ruby
225 | class ApiTest < Bbq::TestCase
226 | background do
227 | headers = {'HTTP_ACCEPT' => 'application/json'}
228 | @client = TestClient.new(:headers => headers)
229 | end
230 |
231 | scenario "admin can browse all user tickets" do
232 | @client.get "/unicorn" do |response|
233 | assert_equal 200, response.status
234 | assert_equal "pink", response.body["unicorn"]["color"]
235 | end
236 | @client.post "/ponies", { :name => "Miracle" } do |response|
237 | assert_equal 200, response.status
238 | end
239 | end
240 | end
241 | ```
242 |
243 | ## Rails URL Helpers
244 |
245 | Using url helpers from Rails in integration tests is not recommended.
246 | Testing routes is part of integration test, so you should actually use only
247 |
248 | ```ruby
249 | visit '/'
250 | ```
251 |
252 | in your integration test. Use links and buttons in order to get to other pages in your app.
253 |
254 | If you really need url helpers in your test user, just include them in your TestUser class:
255 |
256 | ```ruby
257 | require 'bbq/rails/routes'
258 |
259 | class TestUser < Bbq::TestUser
260 | include Bbq::Rails::Routes
261 | end
262 | ```
263 | or just
264 |
265 | ```ruby
266 | class TestUser < Bbq::TestUser
267 | include ::ActionDispatch::Routing::UrlFor
268 | include ::Rails.application.routes.url_helpers
269 | include ::ActionDispatch::Routing::RouteSet::MountedHelpers unless ::Rails.version < "3.1"
270 | end
271 | ```
272 |
273 | ## Devise support
274 |
275 | ```ruby
276 | require "bbq/test_user"
277 | require "bbq/devise"
278 |
279 | class TestUser < Bbq::TestUser
280 | include Bbq::Devise
281 | end
282 | ```
283 |
284 | After that TestUser have *login*, *logout*, *register*, *register_and_login* methods.
285 |
286 | ```ruby
287 | test "user register with devise" do
288 | user = TestUser.new # or TestUser.new(:email => "email@example.com", :password => "secret")
289 | user.register_and_login
290 | user.see!("Stuff after auth")
291 | end
292 | ```
293 |
294 | ## Caveats
295 |
296 | ### Timeout::Error
297 |
298 | If you simulate multiple users in your tests and spawn multiple browsers with selenium it might
299 | be a good idea to use Thin instead of Webrick to create application server.
300 | We have experienced some problems with Webrick that lead to `Timeout::Error` exception
301 | when user/browser that was inactive for some time (due to other users/browsers
302 | activities) was requested to execute an action.
303 |
304 | Capybara will use Thin instead of Webrick when it's available, so you only need to add Thin to you Gemfile:
305 |
306 | ```ruby
307 | # In test group if you want it to
308 | # be used only in tests and not in your development mode
309 | # ex. when running 'rails s'
310 |
311 | gem 'thin', :require => false
312 | ```
313 |
314 | ## Additional information
315 |
316 | * [2 problems with Cucumber](http://andrzejonsoftware.blogspot.com/2011/03/2-problems-with-cucumber.html)
317 | * [Object oriented acceptance testing](http://andrzejonsoftware.blogspot.com/2011/04/object-oriented-acceptance-testing.html)
318 |
319 |
--------------------------------------------------------------------------------
/bbq-core/README.md:
--------------------------------------------------------------------------------
1 | # BBQ
2 |
3 | [](http://travis-ci.org/drugpl/bbq-core) [](https://gemnasium.com/drugpl/bbq-core) [](https://codeclimate.com/github/drugpl/bbq-core) [](http://badge.fury.io/rb/bbq-core)
4 |
5 | Object oriented acceptance testing using personas.
6 |
7 | * Ruby (no Gherkin)
8 | * Objects and methods instead of steps
9 | * Test framework independent (RSpec and Test::Unit support)
10 | * Thins based on Capybara.
11 | * DCI (Data Context Interaction) for roles/personas
12 | * Opinionated
13 |
14 | ## Setup
15 |
16 | First, add BBQ to your apps `Gemfile`:
17 |
18 | ```ruby
19 | gem "bbq", "0.2.1"
20 | ```
21 |
22 | Run install generator:
23 |
24 | ```
25 | bundle exec rails generate bbq:install
26 | ```
27 |
28 | Require BBQ in test/test_helper.rb (in case of Test::Unit):
29 |
30 | ```ruby
31 | require "bbq/test_unit"
32 | ```
33 |
34 | Require BBQ in spec/spec_helper.rb (in case of RSpec):
35 |
36 | ```ruby
37 | require "bbq/rspec"
38 | ```
39 |
40 | ## Feature generator
41 |
42 | ```
43 | bundle exec rails g bbq:test MyFeatureName
44 | ```
45 |
46 | ## Running features
47 |
48 | For Test::Unit flavour:
49 |
50 | ```
51 | bundle exec rake test:acceptance
52 | ```
53 |
54 | For RSpec flavour:
55 |
56 | ```
57 | bundle exec rake spec:acceptance
58 | ```
59 |
60 | ## Examples
61 |
62 | ### Roles and Devise integration
63 |
64 | ```ruby
65 | class TestUser < Bbq::TestUser
66 | include Bbq::Devise
67 |
68 | def update_ticket(summary, comment)
69 | show_ticket(summary)
70 | fill_in "Comment", :with => comment
71 | click_on "Add update"
72 | end
73 |
74 | def open_application
75 | visit '/'
76 | end
77 |
78 | module TicketReporter
79 | def open_tickets_listing
80 | open_application
81 | click_link 'Tickets'
82 | end
83 |
84 | def open_ticket(summary, description)
85 | open_tickets_listing
86 | click_on "Open a new ticket"
87 | fill_in "Summary", :with => summary
88 | fill_in "Description", :with => description
89 | click_on "Open ticket"
90 | end
91 |
92 | def show_ticket(summary)
93 | open_tickets_listing
94 | click_on summary
95 | end
96 | end
97 |
98 | module TicketManager
99 | def open_administration
100 | visit '/admin'
101 | end
102 |
103 | def open_tickets_listing
104 | open_administration
105 | click_link 'Tickets'
106 | end
107 |
108 | def close_ticket(summary, comment = nil)
109 | open_tickets_listing
110 | click_on summary
111 | fill_in "Comment", :with => comment if comment
112 | click_on "Close ticket"
113 | end
114 |
115 | def show_ticket(summary)
116 | open_tickets_listing
117 | click_on summary
118 | end
119 | end
120 | end
121 | ```
122 |
123 | ```ruby
124 | class AdminTicketsTest < Bbq::TestCase
125 | background do
126 | admin = Factory(:admin)
127 | @email, @password = admin.email, admin.password
128 | end
129 |
130 | scenario "admin can browse all user tickets" do
131 | summaries = ["Forgot my password", "Page is not displayed correctly"]
132 | descriptions = ["I lost my yellow note with password under the table!",
133 | "My IE renders crap instead of crispy fonts!"]
134 |
135 | alice = TestUser.new
136 | alice.roles(:ticket_reporter)
137 | alice.register_and_login
138 | alice.open_ticket(summaries.first, descriptions.first)
139 |
140 | bob = TestUser.new
141 | bob.roles(:ticket_reporter)
142 | bob.register_and_login
143 | bob.open_ticket(summaries.second, descriptions.second)
144 |
145 | charlie = TestUser.new(:email => @email, :password => @password)
146 | charlie.login # charlie was already "registered" in factory as admin
147 | charlie.roles(:ticket_manager)
148 | charlie.open_tickets_listing
149 | charlie.see!(*summaries)
150 |
151 | charlie.click_on(summaries.second)
152 | charlie.see!(summaries.second, descriptions.second)
153 | charlie.not_see!(summaries.first, descriptions.first)
154 | end
155 | end
156 | ```
157 |
158 | ### RSpec integration
159 |
160 | ```ruby
161 | class TestUser < Bbq::TestUser
162 | def email
163 | @options[:email] || "buyer@example.com"
164 | end
165 |
166 | module Buyer
167 | def ask_question(question)
168 | fill_in "question", :with => question
169 | fill_in "email", :with => email
170 | click_on("Ask")
171 | end
172 |
173 | def go_to_page_and_open_widget(page_url, &block)
174 | go_to_page(page_url)
175 | open_widget &block
176 | end
177 |
178 | def go_to_page(page_url)
179 | visit page_url
180 | wait_until { page.find("iframe") }
181 | end
182 |
183 | def open_widget
184 | within_widget do
185 | page.find("#widget h3").click
186 | yield if block_given?
187 | end
188 | end
189 |
190 | ef within_widget(&block)
191 | within_frame(widget_frame, &block)
192 | end
193 |
194 | def widget_frame
195 | page.evaluate_script("document.getElementsByTagName('iframe')[0].id")
196 | end
197 | end
198 | end
199 | ```
200 |
201 | ```ruby
202 | feature "ask question widget" do
203 | let(:user) {
204 | user = TestUser.new(:driver => :webkit)
205 | user.roles('buyer')
206 | user
207 | }
208 |
209 | scenario "as a guest user, I should be able to ask a question" do
210 | user.go_to_page_and_open_widget("/widget") do
211 | user.ask_question "my question"
212 | user.see!("Thanks!")
213 | end
214 | end
215 | end
216 | ```
217 |
218 | ## Testing REST APIs
219 |
220 | Bbq provides `Bbq::TestClient`, similar to `Bbq::TestUser`, but intended for testing APIs.
221 | It's a thin wrapper around `Rack::Test` which allows you to send requests and run assertions
222 | against responses.
223 |
224 | ```ruby
225 | class ApiTest < Bbq::TestCase
226 | background do
227 | headers = {'HTTP_ACCEPT' => 'application/json'}
228 | @client = TestClient.new(:headers => headers)
229 | end
230 |
231 | scenario "admin can browse all user tickets" do
232 | @client.get "/unicorn" do |response|
233 | assert_equal 200, response.status
234 | assert_equal "pink", response.body["unicorn"]["color"]
235 | end
236 | @client.post "/ponies", { :name => "Miracle" } do |response|
237 | assert_equal 200, response.status
238 | end
239 | end
240 | end
241 | ```
242 |
243 | ## Rails URL Helpers
244 |
245 | Using url helpers from Rails in integration tests is not recommended.
246 | Testing routes is part of integration test, so you should actually use only
247 |
248 | ```ruby
249 | visit '/'
250 | ```
251 |
252 | in your integration test. Use links and buttons in order to get to other pages in your app.
253 |
254 | If you really need url helpers in your test user, just include them in your TestUser class:
255 |
256 | ```ruby
257 | require 'bbq/rails/routes'
258 |
259 | class TestUser < Bbq::TestUser
260 | include Bbq::Rails::Routes
261 | end
262 | ```
263 | or just
264 |
265 | ```ruby
266 | class TestUser < Bbq::TestUser
267 | include ::ActionDispatch::Routing::UrlFor
268 | include ::Rails.application.routes.url_helpers
269 | include ::ActionDispatch::Routing::RouteSet::MountedHelpers unless ::Rails.version < "3.1"
270 | end
271 | ```
272 |
273 | ## Devise support
274 |
275 | ```ruby
276 | require "bbq/test_user"
277 | require "bbq/devise"
278 |
279 | class TestUser < Bbq::TestUser
280 | include Bbq::Devise
281 | end
282 | ```
283 |
284 | After that TestUser have *login*, *logout*, *register*, *register_and_login* methods.
285 |
286 | ```ruby
287 | test "user register with devise" do
288 | user = TestUser.new # or TestUser.new(:email => "email@example.com", :password => "secret")
289 | user.register_and_login
290 | user.see!("Stuff after auth")
291 | end
292 | ```
293 |
294 | ## Caveats
295 |
296 | ### Timeout::Error
297 |
298 | If you simulate multiple users in your tests and spawn multiple browsers with selenium it might
299 | be a good idea to use Thin instead of Webrick to create application server.
300 | We have experienced some problems with Webrick that lead to `Timeout::Error` exception
301 | when user/browser that was inactive for some time (due to other users/browsers
302 | activities) was requested to execute an action.
303 |
304 | Capybara will use Thin instead of Webrick when it's available, so you only need to add Thin to you Gemfile:
305 |
306 | ```ruby
307 | # In test group if you want it to
308 | # be used only in tests and not in your development mode
309 | # ex. when running 'rails s'
310 |
311 | gem 'thin', :require => false
312 | ```
313 |
314 | ## Additional information
315 |
316 | * [2 problems with Cucumber](http://andrzejonsoftware.blogspot.com/2011/03/2-problems-with-cucumber.html)
317 | * [Object oriented acceptance testing](http://andrzejonsoftware.blogspot.com/2011/04/object-oriented-acceptance-testing.html)
318 |
319 |
--------------------------------------------------------------------------------
/bbq-devise/test/dummy/config/initializers/devise.rb:
--------------------------------------------------------------------------------
1 | require 'devise/version'
2 |
3 | # Use this hook to configure devise mailer, warden hooks and so forth. The first
4 | # four configuration values can also be set straight in your models.
5 | Devise.setup do |config|
6 | config.secret_key = 'a4afae774b0c49455776c2fd27d0e0f632c4553436dffc00d6d5a90fc56ab437a938277fa36ef991c37033d28465598e1ab9be069a7e297dfefd1a658370fb55' if Devise::VERSION.starts_with?("3.")
7 |
8 | # ==> Mailer Configuration
9 | # Configure the e-mail address which will be shown in DeviseMailer.
10 | config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
11 |
12 | # Configure the class responsible to send e-mails.
13 | # config.mailer = "Devise::Mailer"
14 |
15 | # ==> ORM configuration
16 | # Load and configure the ORM. Supports :active_record (default) and
17 | # :mongoid (bson_ext recommended) by default. Other ORMs may be
18 | # available as additional gems.
19 | require 'devise/orm/active_record'
20 |
21 | # ==> Configuration for any authentication mechanism
22 | # Configure which keys are used when authenticating a user. The default is
23 | # just :email. You can configure it to use [:username, :subdomain], so for
24 | # authenticating a user, both parameters are required. Remember that those
25 | # parameters are used only when authenticating and not when retrieving from
26 | # session. If you need permissions, you should implement that in a before filter.
27 | # You can also supply a hash where the value is a boolean determining whether
28 | # or not authentication should be aborted when the value is not present.
29 | # config.authentication_keys = [ :email ]
30 |
31 | # Configure parameters from the request object used for authentication. Each entry
32 | # given should be a request method and it will automatically be passed to the
33 | # find_for_authentication method and considered in your model lookup. For instance,
34 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
35 | # The same considerations mentioned for authentication_keys also apply to request_keys.
36 | # config.request_keys = []
37 |
38 | # Configure which authentication keys should be case-insensitive.
39 | # These keys will be downcased upon creating or modifying a user and when used
40 | # to authenticate or find a user. Default is :email.
41 | config.case_insensitive_keys = [ :email ]
42 |
43 | # Tell if authentication through request.params is enabled. True by default.
44 | # config.params_authenticatable = true
45 |
46 | # Tell if authentication through HTTP Basic Auth is enabled. False by default.
47 | # config.http_authenticatable = false
48 |
49 | # If http headers should be returned for AJAX requests. True by default.
50 | # config.http_authenticatable_on_xhr = true
51 |
52 | # The realm used in Http Basic Authentication. "Application" by default.
53 | # config.http_authentication_realm = "Application"
54 |
55 | # ==> Configuration for :database_authenticatable
56 | # For bcrypt, this is the cost for hashing the password and defaults to 10. If
57 | # using other encryptors, it sets how many times you want the password re-encrypted.
58 | config.stretches = 10
59 |
60 | # Setup a pepper to generate the encrypted password.
61 | # config.pepper = "a433ef8999e265537134701d4ade9b3cd09c66837b24f091bd39ba698456a4462a6393cd2e220b5dd6c9a2376f421d8a068a4a6b46542ba40ad282be61370e21"
62 |
63 | # ==> Configuration for :confirmable
64 | # The time you want to give your user to confirm his account. During this time
65 | # he will be able to access your application without confirming. Default is 0.days
66 | # When confirm_within is zero, the user won't be able to sign in without confirming.
67 | # You can use this to let your user access some features of your application
68 | # without confirming the account, but blocking it after a certain period
69 | # (ie 2 days).
70 | # config.confirm_within = 2.days
71 |
72 | # Defines which key will be used when confirming an account
73 | # config.confirmation_keys = [ :email ]
74 |
75 | # ==> Configuration for :rememberable
76 | # The time the user will be remembered without asking for credentials again.
77 | # config.remember_for = 2.weeks
78 |
79 | # If true, a valid remember token can be re-used between multiple browsers.
80 | # config.remember_across_browsers = true
81 |
82 | # If true, extends the user's remember period when remembered via cookie.
83 | # config.extend_remember_period = false
84 |
85 | # If true, uses the password salt as remember token. This should be turned
86 | # to false if you are not using database authenticatable.
87 | # config.use_salt_as_remember_token = true
88 |
89 | # Options to be passed to the created cookie. For instance, you can set
90 | # :secure => true in order to force SSL only cookies.
91 | # config.cookie_options = {}
92 |
93 | # ==> Configuration for :validatable
94 | # Range for password length. Default is 6..128.
95 | # config.password_length = 6..128
96 |
97 | # Regex to use to validate the email address
98 | # config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
99 |
100 | # ==> Configuration for :timeoutable
101 | # The time you want to timeout the user session without activity. After this
102 | # time the user will be asked for credentials again. Default is 30 minutes.
103 | # config.timeout_in = 30.minutes
104 |
105 | # ==> Configuration for :lockable
106 | # Defines which strategy will be used to lock an account.
107 | # :failed_attempts = Locks an account after a number of failed attempts to sign in.
108 | # :none = No lock strategy. You should handle locking by yourself.
109 | # config.lock_strategy = :failed_attempts
110 |
111 | # Defines which key will be used when locking and unlocking an account
112 | # config.unlock_keys = [ :email ]
113 |
114 | # Defines which strategy will be used to unlock an account.
115 | # :email = Sends an unlock link to the user email
116 | # :time = Re-enables login after a certain amount of time (see :unlock_in below)
117 | # :both = Enables both strategies
118 | # :none = No unlock strategy. You should handle unlocking by yourself.
119 | # config.unlock_strategy = :both
120 |
121 | # Number of authentication tries before locking an account if lock_strategy
122 | # is failed attempts.
123 | # config.maximum_attempts = 20
124 |
125 | # Time interval to unlock the account if :time is enabled as unlock_strategy.
126 | # config.unlock_in = 1.hour
127 |
128 | # ==> Configuration for :recoverable
129 | #
130 | # Defines which key will be used when recovering the password for an account
131 | # config.reset_password_keys = [ :email ]
132 |
133 | # Time interval you can reset your password with a reset password key.
134 | # Don't put a too small interval or your users won't have the time to
135 | # change their passwords.
136 | config.reset_password_within = 2.hours
137 |
138 | # ==> Configuration for :encryptable
139 | # Allow you to use another encryption algorithm besides bcrypt (default). You can use
140 | # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
141 | # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
142 | # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
143 | # REST_AUTH_SITE_KEY to pepper)
144 | # config.encryptor = :sha512
145 |
146 | # ==> Configuration for :token_authenticatable
147 | # Defines name of the authentication token params key
148 | # config.token_authentication_key = :auth_token
149 |
150 | # If true, authentication through token does not store user in session and needs
151 | # to be supplied on each request. Useful if you are using the token as API token.
152 | # config.stateless_token = false
153 |
154 | # ==> Scopes configuration
155 | # Turn scoped views on. Before rendering "sessions/new", it will first check for
156 | # "users/sessions/new". It's turned off by default because it's slower if you
157 | # are using only default views.
158 | # config.scoped_views = false
159 |
160 | # Configure the default scope given to Warden. By default it's the first
161 | # devise role declared in your routes (usually :user).
162 | # config.default_scope = :user
163 |
164 | # Configure sign_out behavior.
165 | # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
166 | # The default is true, which means any logout action will sign out all active scopes.
167 | # config.sign_out_all_scopes = true
168 |
169 | # ==> Navigation configuration
170 | # Lists the formats that should be treated as navigational. Formats like
171 | # :html, should redirect to the sign in page when the user does not have
172 | # access, but formats like :xml or :json, should return 401.
173 | #
174 | # If you have any extra navigational formats, like :iphone or :mobile, you
175 | # should add them to the navigational formats lists.
176 | #
177 | # The :"*/*" and "*/*" formats below is required to match Internet
178 | # Explorer requests.
179 | # config.navigational_formats = [:"*/*", "*/*", :html]
180 |
181 | # The default HTTP method used to sign out a resource. Default is :get.
182 | # config.sign_out_via = :get
183 |
184 | # ==> OmniAuth
185 | # Add a new OmniAuth provider. Check the wiki for more information on setting
186 | # up on your models and hooks.
187 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
188 |
189 | # ==> Warden configuration
190 | # If you want to use other strategies, that are not supported by Devise, or
191 | # change the failure app, you can configure them inside the config.warden block.
192 | #
193 | # config.warden do |manager|
194 | # manager.failure_app = AnotherApp
195 | # manager.intercept_401 = false
196 | # manager.default_strategies(:scope => :user).unshift :some_external_strategy
197 | # end
198 | end
199 |
--------------------------------------------------------------------------------