bbq 0.0.1 → 0.0.2.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +8 -0
  3. data/Gemfile +2 -1
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +152 -0
  6. data/Rakefile +29 -1
  7. data/bbq.gemspec +14 -4
  8. data/lib/bbq.rb +5 -1
  9. data/lib/bbq/devise.rb +53 -0
  10. data/lib/bbq/railtie.rb +7 -0
  11. data/lib/bbq/rspec.rb +86 -0
  12. data/lib/bbq/test.rb +36 -0
  13. data/lib/bbq/test_user.rb +61 -0
  14. data/lib/bbq/util.rb +19 -0
  15. data/lib/bbq/version.rb +1 -1
  16. data/lib/generators/bbq/install_generator.rb +5 -0
  17. data/lib/generators/bbq/test_generator.rb +5 -0
  18. data/lib/generators/rspec/bbq_install_generator.rb +18 -0
  19. data/lib/generators/rspec/bbq_test_generator.rb +9 -0
  20. data/lib/generators/rspec/templates/README +5 -0
  21. data/lib/generators/rspec/templates/bbq_spec.rb +7 -0
  22. data/lib/generators/rspec/templates/test_user.rb +5 -0
  23. data/lib/generators/test_unit/bbq_install_generator.rb +18 -0
  24. data/lib/generators/test_unit/bbq_test_generator.rb +9 -0
  25. data/lib/generators/test_unit/templates/README +5 -0
  26. data/lib/generators/test_unit/templates/bbq_test_case.rb +7 -0
  27. data/lib/generators/test_unit/templates/test_user.rb +5 -0
  28. data/lib/tasks/bbq.rake +15 -0
  29. data/test/dummy/Rakefile +7 -0
  30. data/test/dummy/app/controllers/application_controller.rb +3 -0
  31. data/test/dummy/app/controllers/home_controller.rb +11 -0
  32. data/test/dummy/app/helpers/application_helper.rb +2 -0
  33. data/test/dummy/app/models/user.rb +6 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/config.ru +4 -0
  36. data/test/dummy/config/application.rb +46 -0
  37. data/test/dummy/config/boot.rb +10 -0
  38. data/test/dummy/config/database.yml +3 -0
  39. data/test/dummy/config/environment.rb +5 -0
  40. data/test/dummy/config/environments/development.rb +26 -0
  41. data/test/dummy/config/environments/production.rb +49 -0
  42. data/test/dummy/config/environments/test.rb +35 -0
  43. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/test/dummy/config/initializers/devise.rb +194 -0
  45. data/test/dummy/config/initializers/inflections.rb +10 -0
  46. data/test/dummy/config/initializers/mime_types.rb +5 -0
  47. data/test/dummy/config/initializers/secret_token.rb +7 -0
  48. data/test/dummy/config/initializers/session_store.rb +8 -0
  49. data/test/dummy/config/locales/en.yml +5 -0
  50. data/test/dummy/config/routes.rb +6 -0
  51. data/test/dummy/db/schema.rb +19 -0
  52. data/test/dummy/public/404.html +26 -0
  53. data/test/dummy/public/422.html +26 -0
  54. data/test/dummy/public/500.html +26 -0
  55. data/test/dummy/public/favicon.ico +0 -0
  56. data/test/dummy/script/rails +6 -0
  57. data/test/dummy/spec/spec_helper.rb +10 -0
  58. data/test/dummy/test/test_helper.rb +2 -0
  59. data/test/support/helpers.rb +14 -0
  60. data/test/test_helper.rb +20 -0
  61. data/test/unit/bbq_devise_test.rb +39 -0
  62. data/test/unit/bbq_install_generator_test.rb +37 -0
  63. data/test/unit/bbq_rspec_test.rb +63 -0
  64. data/test/unit/bbq_test_generator_test.rb +23 -0
  65. data/test/unit/bbq_test_unit_test.rb +31 -0
  66. data/test/unit/bbq_test_user_test.rb +56 -0
  67. data/test/unit/bbq_two_simultaneous_users_test.rb +55 -0
  68. data/test/unit/bbq_util_test.rb +40 -0
  69. metadata +153 -11
@@ -0,0 +1,61 @@
1
+ require 'capybara/rails'
2
+ require 'capybara/dsl'
3
+ require 'bbq/util'
4
+
5
+ module Bbq
6
+
7
+ class TestUser
8
+
9
+ include ActionDispatch::Routing::UrlFor
10
+ include Rails.application.routes.url_helpers
11
+ include Capybara::DSL
12
+
13
+ attr_reader :options
14
+
15
+ class << self
16
+ attr_accessor :callbacks
17
+ end
18
+
19
+ def initialize(options = {})
20
+ @session_name = options.delete(:session_name)
21
+ @current_driver = options.delete(:driver)
22
+ @options = options
23
+
24
+ self.class.callbacks && self.class.callbacks.each do |callback|
25
+ callback[:extension].send(callback[:method], self)
26
+ end
27
+ end
28
+
29
+ def page
30
+ Capybara.using_session(session_name) do
31
+ Capybara.current_session
32
+ end
33
+ end
34
+
35
+ def session_name
36
+ @session_name ||= ActiveSupport::SecureRandom.hex(8)
37
+ end
38
+
39
+ def roles(*names)
40
+ names.each do |name|
41
+ module_obj = Bbq::Util.find_module(name, self)
42
+ self.extend(module_obj)
43
+ end
44
+ end
45
+
46
+ def self.add_callback(extension, method=:init)
47
+ self.callbacks ||= []
48
+ self.callbacks << {:extension => extension, :method => method}
49
+ end
50
+
51
+ def see?(*args)
52
+ args.all? { |arg| has_content?(arg) }
53
+ end
54
+
55
+ def not_see?(*args)
56
+ args.all? { |arg| has_no_content?(arg) }
57
+ end
58
+
59
+ end
60
+
61
+ end
data/lib/bbq/util.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+
3
+ module Bbq
4
+ class Util
5
+ def self.find_module(name, scope = nil)
6
+ namespace = case scope
7
+ when String, Symbol
8
+ "::#{scope.to_s.camelize}"
9
+ when Class
10
+ "::#{scope.name}"
11
+ when NilClass
12
+ nil
13
+ else
14
+ "::#{scope.class.name}"
15
+ end
16
+ "#{namespace}::#{name.to_s.camelize}".constantize
17
+ end
18
+ end
19
+ end
data/lib/bbq/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bbq
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2.beta.1"
3
3
  end
@@ -0,0 +1,5 @@
1
+ module Bbq
2
+ class InstallGenerator < Rails::Generators::Base
3
+ hook_for :test_framework, :aliases => "-t", :as => "bbq_install"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Bbq
2
+ class TestGenerator < Rails::Generators::NamedBase
3
+ hook_for :test_framework, :aliases => "-t", :as => "bbq_test"
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module Rspec
2
+ class BbqInstallGenerator < Rails::Generators::Base
3
+ source_root Bbq.root.join("lib/generators/rspec/templates")
4
+
5
+ def create_directory
6
+ empty_directory "spec/acceptance"
7
+ end
8
+
9
+ def generate_test_user
10
+ empty_directory "spec/support"
11
+ template "test_user.rb", "spec/support/test_user.rb"
12
+ end
13
+
14
+ def show_readme
15
+ readme "README" if behavior == :invoke
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Rspec
2
+ class BbqTestGenerator < Rails::Generators::NamedBase
3
+ source_root Bbq.root.join("lib/generators/rspec/templates")
4
+
5
+ def create_test
6
+ template "bbq_spec.rb", "spec/acceptance/#{name.underscore}_spec.rb"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+
2
+ To finish setup, place in your spec/spec_helper.rb the following:
3
+
4
+ require 'bbq/rspec'
5
+
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ feature "<%= name.underscore.capitalize.gsub(/_/, ' ') %>" do
4
+ scenario "the truth" do
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ class TestUser < Bbq::TestUser
4
+ # FIXME: explain here how to extend TestUser
5
+ end
@@ -0,0 +1,18 @@
1
+ module TestUnit
2
+ class BbqInstallGenerator < Rails::Generators::Base
3
+ source_root Bbq.root.join("lib/generators/test_unit/templates")
4
+
5
+ def create_directory
6
+ empty_directory "test/acceptance"
7
+ end
8
+
9
+ def generate_test_user
10
+ empty_directory "test/support"
11
+ template "test_user.rb", "test/support/test_user.rb"
12
+ end
13
+
14
+ def show_readme
15
+ readme "README" if behavior == :invoke
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module TestUnit
2
+ class BbqTestGenerator < Rails::Generators::NamedBase
3
+ source_root Bbq.root.join("lib/generators/test_unit/templates")
4
+
5
+ def create_test
6
+ template "bbq_test_case.rb", "test/acceptance/#{name.underscore}_test.rb"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+
2
+ To finish setup, place in your test/test_helper.rb the following:
3
+
4
+ require 'bbq/test'
5
+
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ class <%= name.classify %>Test < Bbq::TestCase
4
+ scenario "the truth" do
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require "test_helper"
2
+
3
+ class TestUser < Bbq::TestUser
4
+ # FIXME: explain here how to extend TestUser
5
+ end
@@ -0,0 +1,15 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new("test:acceptance") do |t|
4
+ t.libs << 'test'
5
+ t.pattern = 'test/acceptance/*_test.rb'
6
+ t.verbose = false
7
+ end if File.exists?('test/acceptance')
8
+
9
+ begin
10
+ require 'rspec/core/rake_task'
11
+ RSpec::Core::RakeTask.new('spec:acceptance') do |spec|
12
+ spec.pattern = FileList['spec/acceptance/*_spec.rb']
13
+ end if File.exists?('spec/acceptance')
14
+ rescue LoadError
15
+ end
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,11 @@
1
+ class HomeController < ApplicationController
2
+ before_filter :authenticate_user!, :only => :index
3
+
4
+ def index
5
+ render :text => "BBQ"
6
+ end
7
+
8
+ def miracle
9
+ render :text => "MIRACLE"
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,6 @@
1
+ class User < ActiveRecord::Base
2
+ devise :database_authenticatable, :registerable,
3
+ :recoverable, :rememberable, :trackable, :validatable
4
+
5
+ attr_accessible :email, :password, :password_confirmation, :remember_me
6
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,46 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ require "bbq"
11
+ require "devise"
12
+
13
+ module Dummy
14
+ class Application < Rails::Application
15
+ # Settings in config/environments/* take precedence over those specified here.
16
+ # Application configuration should go into files in config/initializers
17
+ # -- all .rb files in that directory are automatically loaded.
18
+
19
+ # Custom directories with classes and modules you want to be autoloadable.
20
+ # config.autoload_paths += %W(#{config.root}/extras)
21
+
22
+ # Only load the plugins named here, in the order given (default is alphabetical).
23
+ # :all can be used as a placeholder for all plugins not explicitly named.
24
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
25
+
26
+ # Activate observers that should always be running.
27
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
28
+
29
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
30
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
31
+ # config.time_zone = 'Central Time (US & Canada)'
32
+
33
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
34
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
35
+ # config.i18n.default_locale = :de
36
+
37
+ # JavaScript files you want as :defaults (application.js is always included).
38
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
39
+
40
+ # Configure the default encoding used in templates for Ruby 1.9.
41
+ config.encoding = "utf-8"
42
+
43
+ # Configure sensitive parameters which will be filtered from the log file.
44
+ config.filter_parameters += [:password]
45
+ end
46
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: ":memory:"
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,26 @@
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
+
@@ -0,0 +1,49 @@
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
@@ -0,0 +1,35 @@
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