aktion_test_rails 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rvmrc +1 -1
- data/.travis.yml +3 -6
- data/CHANGELOG.md +35 -0
- data/Gemfile +18 -3
- data/README.md +12 -1
- data/Rakefile +2 -8
- data/aktion_test_rails.gemspec +1 -4
- data/lib/aktion_test_rails/load.rb +18 -0
- data/lib/aktion_test_rails/matchers/active_admin/flash.rb +93 -0
- data/lib/aktion_test_rails/matchers/active_admin.rb +50 -0
- data/lib/aktion_test_rails/matchers/factory_girl/validation.rb +58 -0
- data/lib/aktion_test_rails/matchers/factory_girl.rb +7 -2
- data/lib/aktion_test_rails/support/active_admin/request/sign_in.rb +17 -0
- data/lib/aktion_test_rails/support/active_admin/request.rb +16 -0
- data/lib/aktion_test_rails/support/capybara/rack_app.rb +13 -0
- data/lib/aktion_test_rails/support/rails/model_builder.rb +59 -0
- data/lib/aktion_test_rails/version.rb +1 -1
- data/lib/aktion_test_rails.rb +56 -3
- data/spec/aktion_test_rails/model_builder_spec.rb +68 -0
- data/spec/matchers/active_admin/flash_spec.rb +141 -0
- data/spec/matchers/factory_girl/validation_spec.rb +71 -0
- data/spec/rails_app/.gitignore +15 -0
- data/spec/rails_app/Rakefile +7 -0
- data/spec/rails_app/app/admin/admin_user.rb +22 -0
- data/spec/rails_app/app/admin/dashboard.rb +33 -0
- data/spec/rails_app/app/assets/images/.gitkeep +0 -0
- data/spec/rails_app/app/assets/javascripts/active_admin.js +1 -0
- data/spec/rails_app/app/assets/javascripts/application.js +15 -0
- data/spec/rails_app/app/assets/stylesheets/active_admin.css.scss +29 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +13 -0
- data/spec/rails_app/app/controllers/application_controller.rb +3 -0
- data/spec/rails_app/app/models/admin_user.rb +11 -0
- data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
- data/spec/rails_app/config/application.rb +19 -0
- data/spec/rails_app/config/boot.rb +3 -0
- data/spec/rails_app/config/database.yml +5 -0
- data/spec/rails_app/config/environment.rb +2 -0
- data/spec/rails_app/config/environments/test.rb +37 -0
- data/spec/rails_app/config/initializers/active_admin.rb +7 -0
- data/spec/rails_app/config/initializers/devise.rb +11 -0
- data/spec/rails_app/config/initializers/secret_token.rb +1 -0
- data/spec/rails_app/config/initializers/session_store.rb +1 -0
- data/spec/rails_app/config/initializers/wrap_parameters.rb +6 -0
- data/spec/rails_app/config/locales/devise.en.yml +58 -0
- data/spec/rails_app/config/locales/en.yml +9 -0
- data/spec/rails_app/config/routes.rb +5 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/db/migrate/20121126141714_devise_create_admin_users.rb +52 -0
- data/spec/rails_app/db/migrate/20121126141717_create_admin_notes.rb +17 -0
- data/spec/rails_app/db/migrate/20121126141718_move_admin_notes_to_comments.rb +25 -0
- data/spec/rails_app/public/404.html +26 -0
- data/spec/rails_app/public/422.html +26 -0
- data/spec/rails_app/public/500.html +25 -0
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/public/robots.txt +5 -0
- data/spec/rails_app/script/rails +6 -0
- data/spec/requests/active_admin/sign_in_spec.rb +34 -0
- data/spec/spec_active_record.rb +13 -0
- data/spec/spec_base.rb +28 -0
- data/spec/spec_rails.rb +18 -0
- metadata +99 -60
- data/Appraisals +0 -15
- data/gemfiles/3.0.gemfile +0 -8
- data/gemfiles/3.0.gemfile.lock +0 -175
- data/gemfiles/3.1.gemfile +0 -10
- data/gemfiles/3.1.gemfile.lock +0 -196
- data/gemfiles/3.2.gemfile +0 -10
- data/gemfiles/3.2.gemfile.lock +0 -194
- data/lib/aktion_test_rails/class_builder.rb +0 -29
- data/lib/aktion_test_rails/matchers/factory_girl/have_a_valid_factory.rb +0 -49
- data/lib/aktion_test_rails/matchers/integrations/rspec.rb +0 -9
- data/lib/aktion_test_rails/matchers.rb +0 -1
- data/lib/aktion_test_rails/model_builder.rb +0 -70
- data/spec/matchers/factory_girl/have_a_valid_factory_spec.rb +0 -64
- data/spec/spec_helper.rb +0 -27
@@ -1,29 +0,0 @@
|
|
1
|
-
module AktionTestRails
|
2
|
-
module ClassBuilder
|
3
|
-
def self.included(example_group)
|
4
|
-
example_group.class_eval do
|
5
|
-
after do
|
6
|
-
teardown_defined_constants
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def define_class(class_name, base = Object, &block)
|
12
|
-
class_name = class_name.to_s.camelize
|
13
|
-
|
14
|
-
Class.new(base).tap do |constant_class|
|
15
|
-
Object.const_set(class_name, constant_class)
|
16
|
-
constant_class.unloadable
|
17
|
-
constant_class.class_eval(&block) if block_given?
|
18
|
-
constant_class.reset_column_information if constant_class.respond_to? :reset_column_information
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def teardown_defined_constants
|
23
|
-
ActiveSupport::Dependencies.clear
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
RSpec.configure {|config| config.include AktionTestRails::ClassBuilder}
|
29
|
-
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module AktionTestRails
|
2
|
-
module Matchers
|
3
|
-
module FactoryGirl
|
4
|
-
def have_a_valid_factory(factory_name)
|
5
|
-
ValidFactoryMatcher.new(factory_name)
|
6
|
-
end
|
7
|
-
|
8
|
-
class ValidFactoryMatcher
|
9
|
-
def initialize(factory_name)
|
10
|
-
@factory_name = factory_name
|
11
|
-
end
|
12
|
-
|
13
|
-
def matches?(subject)
|
14
|
-
factory_exists? && factory_creates_valid_record?
|
15
|
-
end
|
16
|
-
|
17
|
-
def failure_message
|
18
|
-
message = "Expected :#{@factory_name} to be a valid factory."
|
19
|
-
if factory_exists?
|
20
|
-
if @record.errors.full_messages.any?
|
21
|
-
message << "\n Failed Validations:"
|
22
|
-
@record.errors.full_messages.each do |error|
|
23
|
-
message << "\n #{error}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
else
|
27
|
-
message << "\n No factory by the name :#{@factory_name} found"
|
28
|
-
end
|
29
|
-
message
|
30
|
-
end
|
31
|
-
|
32
|
-
def description
|
33
|
-
"has a valid factory named :#{@factory_name}"
|
34
|
-
end
|
35
|
-
|
36
|
-
protected
|
37
|
-
|
38
|
-
def factory_exists?
|
39
|
-
::FactoryGirl.factories.registered?(@factory_name)
|
40
|
-
end
|
41
|
-
|
42
|
-
def factory_creates_valid_record?
|
43
|
-
@record = ::FactoryGirl.build(@factory_name)
|
44
|
-
@record.valid?
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'aktion_test_rails/matchers/integrations/rspec'
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module AktionTestRails
|
2
|
-
module ModelBuilder
|
3
|
-
def self.included(example_group)
|
4
|
-
example_group.class_eval do
|
5
|
-
before do
|
6
|
-
@created_tables ||= []
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
drop_created_tables
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def create_table(table_name, options = {}, &block)
|
16
|
-
connection = ActiveRecord::Base.connection
|
17
|
-
|
18
|
-
begin
|
19
|
-
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
20
|
-
connection.create_table(table_name, options, &block)
|
21
|
-
@created_tables << table_name
|
22
|
-
connection
|
23
|
-
rescue Exception => e
|
24
|
-
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
25
|
-
raise e
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def define_model_class(class_name, &block)
|
30
|
-
define_class(class_name, ActiveRecord::Base, &block)
|
31
|
-
end
|
32
|
-
|
33
|
-
def define_active_model_class(class_name, options = {}, &block)
|
34
|
-
define_class(class_name) do
|
35
|
-
include ActiveModel::Validations
|
36
|
-
|
37
|
-
options[:accessors].each do |column|
|
38
|
-
attr_accessor column.to_sym
|
39
|
-
end
|
40
|
-
|
41
|
-
class_eval(&block) if block_given?
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def define_model(name, columns = {}, &block)
|
46
|
-
class_name = name.to_s.pluralize.classify
|
47
|
-
table_name = class_name.tableize
|
48
|
-
|
49
|
-
create_table(table_name) do |table|
|
50
|
-
columns.each do |name,type|
|
51
|
-
table.column name, type
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
define_model_class(class_name, &block)
|
56
|
-
end
|
57
|
-
|
58
|
-
def drop_created_tables
|
59
|
-
connection = ActiveRecord::Base.connection
|
60
|
-
|
61
|
-
@created_tables.each do |table_name|
|
62
|
-
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
RSpec.configure do |config|
|
69
|
-
config.include AktionTestRails::ModelBuilder
|
70
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe AktionTestRails::Matchers::FactoryGirl::ValidFactoryMatcher do
|
4
|
-
let(:matcher_class) { AktionTestRails::Matchers::FactoryGirl::ValidFactoryMatcher }
|
5
|
-
|
6
|
-
after(:each) do
|
7
|
-
FactoryGirl.factories.clear
|
8
|
-
end
|
9
|
-
|
10
|
-
it "accepts a valid factory" do
|
11
|
-
define_model :user, :name => :string
|
12
|
-
FactoryGirl.define do
|
13
|
-
factory :user do
|
14
|
-
name "Name"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
User.new.should have_a_valid_factory(:user)
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when the factory does not exist" do
|
22
|
-
before(:each) { define_model :user }
|
23
|
-
|
24
|
-
it "does not accept the factory" do
|
25
|
-
User.new.should_not have_a_valid_factory(:user)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "says that the factory does not exist" do
|
29
|
-
matcher = matcher_class.new(:user).tap{|m| m.matches?(User.new)}
|
30
|
-
expected_message = <<-ERROR
|
31
|
-
Expected :user to be a valid factory.
|
32
|
-
No factory by the name :user found
|
33
|
-
ERROR
|
34
|
-
matcher.failure_message.should == expected_message.strip
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when the factory has validation errors' do
|
39
|
-
before(:each) do
|
40
|
-
define_model :user, :name => :string do
|
41
|
-
validates_presence_of :name
|
42
|
-
end
|
43
|
-
FactoryGirl.define do
|
44
|
-
factory :user do
|
45
|
-
name nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it "does not accept the factory" do
|
51
|
-
User.new.should_not have_a_valid_factory(:user)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should detail validation errors with the factory" do
|
55
|
-
matcher = matcher_class.new(:user).tap{|m| m.matches?(User.new)}
|
56
|
-
expected_message = <<-ERROR
|
57
|
-
Expected :user to be a valid factory.
|
58
|
-
Failed Validations:
|
59
|
-
Name can't be blank
|
60
|
-
ERROR
|
61
|
-
matcher.failure_message.should == expected_message.strip
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
TESTAPP_ROOT = File.join(File.dirname(__FILE__), '..', 'tmp', 'testapp')
|
2
|
-
FileUtils.rm_rf(TESTAPP_ROOT) if File.exists?(TESTAPP_ROOT)
|
3
|
-
`rails new #{TESTAPP_ROOT}`
|
4
|
-
|
5
|
-
ENV['RAILS_ENV'] = 'test'
|
6
|
-
ENV['BUNDLE_GEMFILE'] ||= "#{TESTAPP_ROOT}/Gemfile"
|
7
|
-
|
8
|
-
require "#{TESTAPP_ROOT}/config/environment"
|
9
|
-
require 'aktion_test_rails'
|
10
|
-
require 'aktion_test_rails/class_builder'
|
11
|
-
require 'aktion_test_rails/model_builder'
|
12
|
-
|
13
|
-
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
|
14
|
-
|
15
|
-
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
|
16
|
-
|
17
|
-
Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each{|file| require file}
|
18
|
-
|
19
|
-
|
20
|
-
ActiveRecord::Migration.verbose = false
|
21
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
|
22
|
-
|
23
|
-
RSpec.configure do |config|
|
24
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
25
|
-
config.run_all_when_everything_filtered = true
|
26
|
-
config.order = 'random'
|
27
|
-
end
|