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
@@ -0,0 +1,13 @@
|
|
1
|
+
module AktionTestRails
|
2
|
+
module Support
|
3
|
+
module Capybara
|
4
|
+
module RackApp
|
5
|
+
def capybara_rack_app
|
6
|
+
rack_app = -> env { [200, {'Content-Type' => 'text/html'}, [yield(env)]] }
|
7
|
+
::Capybara::Session.new(:rack_test, rack_app)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module AktionTestRails
|
2
|
+
module Support
|
3
|
+
module Rails
|
4
|
+
module ModelBuilder
|
5
|
+
def self.included(example_group)
|
6
|
+
example_group.class_eval do
|
7
|
+
before do
|
8
|
+
@created_tables ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
drop_created_tables
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_table(table_name, options = {}, &block)
|
18
|
+
connection = ActiveRecord::Base.connection
|
19
|
+
|
20
|
+
begin
|
21
|
+
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
22
|
+
connection.create_table(table_name, options, &block)
|
23
|
+
@created_tables << table_name
|
24
|
+
connection
|
25
|
+
rescue Exception => e
|
26
|
+
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
27
|
+
raise e
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def define_model_class(class_name, &block)
|
32
|
+
define_class(class_name, ActiveRecord::Base, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def define_model(name, columns = {}, &block)
|
36
|
+
class_name = name.to_s.pluralize.classify
|
37
|
+
table_name = class_name.tableize
|
38
|
+
|
39
|
+
create_table(table_name) do |table|
|
40
|
+
columns.each do |name,type|
|
41
|
+
table.column name, type
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
define_model_class(class_name, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
def drop_created_tables
|
49
|
+
connection = ActiveRecord::Base.connection
|
50
|
+
|
51
|
+
@created_tables.each do |table_name|
|
52
|
+
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/lib/aktion_test_rails.rb
CHANGED
@@ -1,5 +1,58 @@
|
|
1
|
-
require 'factory_girl_rails'
|
2
1
|
require 'faker'
|
3
|
-
require '
|
2
|
+
require 'aktion_test'
|
4
3
|
require "aktion_test_rails/version"
|
5
|
-
|
4
|
+
|
5
|
+
require 'active_support/dependencies/autoload'
|
6
|
+
require 'active_support/concern'
|
7
|
+
require 'active_support/lazy_load_hooks'
|
8
|
+
|
9
|
+
module AktionTestRails
|
10
|
+
extend ActiveSupport::Autoload
|
11
|
+
|
12
|
+
autoload :ModelBuilder
|
13
|
+
|
14
|
+
module Support
|
15
|
+
module Capybara
|
16
|
+
extend ActiveSupport::Autoload
|
17
|
+
autoload :RackApp
|
18
|
+
end
|
19
|
+
|
20
|
+
module Rails
|
21
|
+
extend ActiveSupport::Autoload
|
22
|
+
autoload :ModelBuilder
|
23
|
+
end
|
24
|
+
|
25
|
+
module ActiveAdmin
|
26
|
+
extend ActiveSupport::Autoload
|
27
|
+
autoload :Request
|
28
|
+
|
29
|
+
ActiveSupport.on_load(:aktion_test_rails_support_active_admin_request) do
|
30
|
+
module Request
|
31
|
+
extend ActiveSupport::Autoload
|
32
|
+
autoload :SignIn
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module Matchers
|
39
|
+
extend ActiveSupport::Autoload
|
40
|
+
|
41
|
+
autoload :ActiveAdmin
|
42
|
+
autoload :FactoryGirl
|
43
|
+
|
44
|
+
ActiveSupport.on_load(:aktion_test_rails_matchers_active_admin) do
|
45
|
+
module ActiveAdmin
|
46
|
+
extend ActiveSupport::Autoload
|
47
|
+
autoload :Flash
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
ActiveSupport.on_load(:aktion_test_rails_matchers_active_admin) do
|
52
|
+
module FactoryGirl
|
53
|
+
extend ActiveSupport::Autoload
|
54
|
+
autoload :Validation
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_base'
|
2
|
+
require 'spec_active_record'
|
3
|
+
|
4
|
+
describe AktionTestRails::Support::Rails::ModelBuilder do
|
5
|
+
include described_class
|
6
|
+
|
7
|
+
describe '#create_table' do
|
8
|
+
it "creates a table" do
|
9
|
+
create_table('test_table')
|
10
|
+
ActiveRecord::Base.connection.table_exists?('test_table').should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "creates a table with columns" do
|
14
|
+
create_table('test_table') do |t|
|
15
|
+
t.column :name, :string
|
16
|
+
end
|
17
|
+
ActiveRecord::Base.connection.columns('test_table').map(&:name).should include('name')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "drops the table if an exception occurs" do
|
21
|
+
ActiveRecord::Base.connection.should_receive(:execute).with('DROP TABLE IF EXISTS test_table').twice
|
22
|
+
ActiveRecord::Base.connection.stub(:create_table) { raise 'error' }
|
23
|
+
create_table('test_table') rescue nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#define_model_class' do
|
28
|
+
it 'creates a class that extends from ActiveRecord::Base' do
|
29
|
+
define_model_class('Foo').superclass.should == ActiveRecord::Base
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'class evals the block on the new class' do
|
33
|
+
create_table('foos')
|
34
|
+
define_model_class('Foo') do
|
35
|
+
attr_accessor :bar
|
36
|
+
end
|
37
|
+
model = Foo.new
|
38
|
+
model.bar = 1
|
39
|
+
model.bar.should == 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#define_model' do
|
44
|
+
it 'creates a table' do
|
45
|
+
define_model('Foo')
|
46
|
+
ActiveRecord::Base.connection.table_exists?('foos').should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'creates a table with the given columns' do
|
50
|
+
define_model('Foo', :name => :string)
|
51
|
+
ActiveRecord::Base.connection.columns('foos').map(&:name).should include('name')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'creates a class that extends from ActiveRecord::Base' do
|
55
|
+
define_model('Foo').superclass.should == ActiveRecord::Base
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'class evals the block on the new class' do
|
59
|
+
create_table('foos')
|
60
|
+
define_model('Foo') do
|
61
|
+
attr_accessor :bar
|
62
|
+
end
|
63
|
+
model = Foo.new
|
64
|
+
model.bar = 1
|
65
|
+
model.bar.should == 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'spec_base'
|
2
|
+
|
3
|
+
describe AktionTestRails::Matchers::ActiveAdmin::Flash do
|
4
|
+
include described_class
|
5
|
+
include AktionTestRails::Support::Capybara::RackApp
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@app = capybara_rack_app do |env|
|
9
|
+
case env['PATH_INFO']
|
10
|
+
when '/test/flash'
|
11
|
+
<<-HTML.strip_heredoc
|
12
|
+
<div class="flash flash_notice">A flash message.</div>
|
13
|
+
HTML
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with a flash notice and a message' do
|
19
|
+
before(:each) { @app.visit '/test/flash' }
|
20
|
+
subject { @app }
|
21
|
+
it { should have_flash(:notice, 'A flash message.') }
|
22
|
+
it { should_not have_flash(:notice, 'Another flash message.') }
|
23
|
+
it { should_not have_flash(:alert, 'A flash message.') }
|
24
|
+
it { should have_flash('A flash message.') }
|
25
|
+
it { should_not have_flash('Another flash message.') }
|
26
|
+
it { should have_flash(:notice) }
|
27
|
+
it { should_not have_flash(:alert) }
|
28
|
+
it { should have_flash }
|
29
|
+
|
30
|
+
describe 'the failure message' do
|
31
|
+
context 'when specifying a flash alert' do
|
32
|
+
it 'explains that a wrong flash was found' do
|
33
|
+
matcher = have_flash(:alert)
|
34
|
+
matcher.matches?(@app)
|
35
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc
|
36
|
+
Expected the page to have a flash alert.
|
37
|
+
|
38
|
+
Found a flash notice.
|
39
|
+
MSG
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when specifying a different message' do
|
44
|
+
it 'shows the expected and actual messages' do
|
45
|
+
matcher = have_flash('Another flash message.')
|
46
|
+
matcher.matches?(@app)
|
47
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc
|
48
|
+
Expected the page to have a flash of `Another flash message.'.
|
49
|
+
|
50
|
+
expected: Another flash message.
|
51
|
+
got: A flash message.
|
52
|
+
MSG
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when specifying a flash alert with a different message' do
|
57
|
+
it 'shows the expected and actual message and explains that a wrong flash was found' do
|
58
|
+
matcher = have_flash(:alert, 'Another flash message.')
|
59
|
+
matcher.matches?(@app)
|
60
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc
|
61
|
+
Expected the page to have a flash alert of `Another flash message.'.
|
62
|
+
|
63
|
+
Found a flash notice.
|
64
|
+
expected: Another flash message.
|
65
|
+
got: A flash message.
|
66
|
+
MSG
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'the negative failure message' do
|
72
|
+
context 'when specifying a matching flash type and message' do
|
73
|
+
it 'explains that the type and message were not expected' do
|
74
|
+
matcher = have_flash(:notice, 'A flash message.')
|
75
|
+
matcher.matches?(@app)
|
76
|
+
matcher.negative_failure_message.should == <<-MSG.strip_heredoc
|
77
|
+
Did not expect the page to have a flash notice of `A flash message.'.
|
78
|
+
|
79
|
+
Flash is a notice.
|
80
|
+
Flash message is `A flash message.'.
|
81
|
+
MSG
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when specifying a matching flash type' do
|
86
|
+
it 'explains that the type was not expected' do
|
87
|
+
matcher = have_flash(:notice)
|
88
|
+
matcher.matches?(@app)
|
89
|
+
matcher.negative_failure_message.should == <<-MSG.strip_heredoc
|
90
|
+
Did not expect the page to have a flash notice.
|
91
|
+
|
92
|
+
Flash is a notice.
|
93
|
+
MSG
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when specifying a mathing flash message' do
|
98
|
+
it 'explains that the message was not expected' do
|
99
|
+
matcher = have_flash('A flash message.')
|
100
|
+
matcher.matches?(@app)
|
101
|
+
matcher.negative_failure_message.should == <<-MSG.strip_heredoc
|
102
|
+
Did not expect the page to have a flash of `A flash message.'.
|
103
|
+
|
104
|
+
Flash message is `A flash message.'.
|
105
|
+
MSG
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'when specifying no flash' do
|
110
|
+
it 'explains that a flash was found, including the type and message' do
|
111
|
+
matcher = have_flash
|
112
|
+
matcher.matches?(@app)
|
113
|
+
matcher.negative_failure_message.should == <<-MSG.strip_heredoc
|
114
|
+
Did not expect the page to have a flash.
|
115
|
+
|
116
|
+
Found a flash notice of `A flash message.'.
|
117
|
+
MSG
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'with no flash' do
|
124
|
+
before(:each) { @app.visit '/test/no_flash' }
|
125
|
+
subject { @app }
|
126
|
+
it { should_not have_flash }
|
127
|
+
|
128
|
+
context 'when specifying a flash' do
|
129
|
+
it 'explains that a flash was not expected' do
|
130
|
+
matcher = have_flash
|
131
|
+
matcher.matches?(@app)
|
132
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc
|
133
|
+
Expected the page to have a flash.
|
134
|
+
|
135
|
+
No flash was found.
|
136
|
+
MSG
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_base'
|
2
|
+
require 'spec_active_record'
|
3
|
+
require 'factory_girl_rails'
|
4
|
+
|
5
|
+
describe AktionTestRails::Matchers::FactoryGirl::Validation do
|
6
|
+
include described_class
|
7
|
+
include AktionTestRails::Support::Rails::ModelBuilder
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
FactoryGirl.factories.clear
|
11
|
+
end
|
12
|
+
|
13
|
+
it "accepts a valid factory" do
|
14
|
+
define_model :user, :name => :string
|
15
|
+
FactoryGirl.define do
|
16
|
+
factory :user do
|
17
|
+
name "Name"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
User.new.should have_valid_factory(:user)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'provides a description for one liners' do
|
25
|
+
have_valid_factory(:user).description.should == "has a valid factory named :user"
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when the factory does not exist" do
|
29
|
+
before(:each) { define_model :user }
|
30
|
+
|
31
|
+
it "does not accept the factory" do
|
32
|
+
User.new.should_not have_valid_factory(:user)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "says that the factory does not exist" do
|
36
|
+
matcher = have_valid_factory(:user).tap{|m| m.matches?(User.new)}
|
37
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc
|
38
|
+
Expected :user to be a valid factory.
|
39
|
+
|
40
|
+
No factory by the name :user found
|
41
|
+
MSG
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when the factory has validation errors' do
|
46
|
+
before(:each) do
|
47
|
+
define_model :user, :name => :string do
|
48
|
+
validates_presence_of :name
|
49
|
+
end
|
50
|
+
FactoryGirl.define do
|
51
|
+
factory :user do
|
52
|
+
name nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "does not accept the factory" do
|
58
|
+
User.new.should_not have_valid_factory(:user)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should detail validation errors with the factory" do
|
62
|
+
matcher = have_valid_factory(:user).tap{|m| m.matches?(User.new)}
|
63
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc
|
64
|
+
Expected :user to be a valid factory.
|
65
|
+
|
66
|
+
Failed Validations:
|
67
|
+
Name can't be blank
|
68
|
+
MSG
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
6
|
+
|
7
|
+
# Ignore bundler config
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
|
13
|
+
# Ignore all logfiles and tempfiles.
|
14
|
+
/log/*.log
|
15
|
+
/tmp
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Testapp::Application.load_tasks
|