aktion_test_rails 0.1.1 → 0.2.0

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 (76) hide show
  1. data/.gitignore +3 -0
  2. data/.rvmrc +1 -1
  3. data/.travis.yml +3 -6
  4. data/CHANGELOG.md +35 -0
  5. data/Gemfile +18 -3
  6. data/README.md +12 -1
  7. data/Rakefile +2 -8
  8. data/aktion_test_rails.gemspec +1 -4
  9. data/lib/aktion_test_rails/load.rb +18 -0
  10. data/lib/aktion_test_rails/matchers/active_admin/flash.rb +93 -0
  11. data/lib/aktion_test_rails/matchers/active_admin.rb +50 -0
  12. data/lib/aktion_test_rails/matchers/factory_girl/validation.rb +58 -0
  13. data/lib/aktion_test_rails/matchers/factory_girl.rb +7 -2
  14. data/lib/aktion_test_rails/support/active_admin/request/sign_in.rb +17 -0
  15. data/lib/aktion_test_rails/support/active_admin/request.rb +16 -0
  16. data/lib/aktion_test_rails/support/capybara/rack_app.rb +13 -0
  17. data/lib/aktion_test_rails/support/rails/model_builder.rb +59 -0
  18. data/lib/aktion_test_rails/version.rb +1 -1
  19. data/lib/aktion_test_rails.rb +56 -3
  20. data/spec/aktion_test_rails/model_builder_spec.rb +68 -0
  21. data/spec/matchers/active_admin/flash_spec.rb +141 -0
  22. data/spec/matchers/factory_girl/validation_spec.rb +71 -0
  23. data/spec/rails_app/.gitignore +15 -0
  24. data/spec/rails_app/Rakefile +7 -0
  25. data/spec/rails_app/app/admin/admin_user.rb +22 -0
  26. data/spec/rails_app/app/admin/dashboard.rb +33 -0
  27. data/spec/rails_app/app/assets/images/.gitkeep +0 -0
  28. data/spec/rails_app/app/assets/javascripts/active_admin.js +1 -0
  29. data/spec/rails_app/app/assets/javascripts/application.js +15 -0
  30. data/spec/rails_app/app/assets/stylesheets/active_admin.css.scss +29 -0
  31. data/spec/rails_app/app/assets/stylesheets/application.css +13 -0
  32. data/spec/rails_app/app/controllers/application_controller.rb +3 -0
  33. data/spec/rails_app/app/models/admin_user.rb +11 -0
  34. data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
  35. data/spec/rails_app/config/application.rb +19 -0
  36. data/spec/rails_app/config/boot.rb +3 -0
  37. data/spec/rails_app/config/database.yml +5 -0
  38. data/spec/rails_app/config/environment.rb +2 -0
  39. data/spec/rails_app/config/environments/test.rb +37 -0
  40. data/spec/rails_app/config/initializers/active_admin.rb +7 -0
  41. data/spec/rails_app/config/initializers/devise.rb +11 -0
  42. data/spec/rails_app/config/initializers/secret_token.rb +1 -0
  43. data/spec/rails_app/config/initializers/session_store.rb +1 -0
  44. data/spec/rails_app/config/initializers/wrap_parameters.rb +6 -0
  45. data/spec/rails_app/config/locales/devise.en.yml +58 -0
  46. data/spec/rails_app/config/locales/en.yml +9 -0
  47. data/spec/rails_app/config/routes.rb +5 -0
  48. data/spec/rails_app/config.ru +4 -0
  49. data/spec/rails_app/db/migrate/20121126141714_devise_create_admin_users.rb +52 -0
  50. data/spec/rails_app/db/migrate/20121126141717_create_admin_notes.rb +17 -0
  51. data/spec/rails_app/db/migrate/20121126141718_move_admin_notes_to_comments.rb +25 -0
  52. data/spec/rails_app/public/404.html +26 -0
  53. data/spec/rails_app/public/422.html +26 -0
  54. data/spec/rails_app/public/500.html +25 -0
  55. data/spec/rails_app/public/favicon.ico +0 -0
  56. data/spec/rails_app/public/robots.txt +5 -0
  57. data/spec/rails_app/script/rails +6 -0
  58. data/spec/requests/active_admin/sign_in_spec.rb +34 -0
  59. data/spec/spec_active_record.rb +13 -0
  60. data/spec/spec_base.rb +28 -0
  61. data/spec/spec_rails.rb +18 -0
  62. metadata +99 -60
  63. data/Appraisals +0 -15
  64. data/gemfiles/3.0.gemfile +0 -8
  65. data/gemfiles/3.0.gemfile.lock +0 -175
  66. data/gemfiles/3.1.gemfile +0 -10
  67. data/gemfiles/3.1.gemfile.lock +0 -196
  68. data/gemfiles/3.2.gemfile +0 -10
  69. data/gemfiles/3.2.gemfile.lock +0 -194
  70. data/lib/aktion_test_rails/class_builder.rb +0 -29
  71. data/lib/aktion_test_rails/matchers/factory_girl/have_a_valid_factory.rb +0 -49
  72. data/lib/aktion_test_rails/matchers/integrations/rspec.rb +0 -9
  73. data/lib/aktion_test_rails/matchers.rb +0 -1
  74. data/lib/aktion_test_rails/model_builder.rb +0 -70
  75. data/spec/matchers/factory_girl/have_a_valid_factory_spec.rb +0 -64
  76. data/spec/spec_helper.rb +0 -27
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  .config
5
5
  .yardoc
6
6
  Gemfile.lock
7
+ !spec/rails_app/Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
9
10
  coverage
@@ -15,3 +16,5 @@ spec/reports
15
16
  test/tmp
16
17
  test/version_tmp
17
18
  tmp
19
+ spec/rails_app/log
20
+ .*.swp
data/.rvmrc CHANGED
@@ -6,7 +6,7 @@
6
6
  # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
7
  # Only full ruby name is supported here, for short names use:
8
8
  # echo "rvm use 1.9.3" > .rvmrc
9
- environment_id="ruby-1.9.3-p194@aktion_test_rails"
9
+ environment_id="ruby-1.9.3-p327@aktion_test_rails"
10
10
 
11
11
  # Uncomment the following lines if you want to verify rvm version per project
12
12
  # rvmrc_rvm_version="1.15.6 (stable)" # 1.10.1 seams as a safe start
data/.travis.yml CHANGED
@@ -1,11 +1,8 @@
1
1
  rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
4
6
 
5
- script: "bundle exec rake spec"
6
-
7
- gemfile:
8
- - gemfiles/3.0.gemfile
9
- - gemfiles/3.1.gemfile
10
- - gemfiles/3.2.gemfile
7
+ script: "bundle exec rake"
11
8
 
data/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
1
+ # v0.2.0
2
+
3
+ * ActiveAdmin request spec sign in support
4
+ * ActiveAdmin flash matcher
5
+ * Moved class builder to AktionTest
6
+ * Improve gem load footprint by moving heavy gems to a different lib file to be loaded
7
+ in spec helpers
8
+ * Relocate code into modules that can be mixed in and lazy loaded easier.
9
+ * Begin supporting Rubinius and JRuby
10
+
11
+ # v0.1.1
12
+
13
+ Bump gem versions
14
+
15
+ # v0.1.0
16
+
17
+ * Added valid factory rspec matcher
18
+ * Added class builder/model builder
19
+
20
+ # v0.0.2
21
+
22
+ More gems
23
+
24
+ * capybara-webkit
25
+ * shoulda-matchers
26
+
27
+ # v0.0.1
28
+
29
+ Add some rails testing gems
30
+
31
+ * rspec-rails
32
+ * cucumber-rails
33
+ * factory_girl_rails
34
+ * capybara
35
+ * and more...
data/Gemfile CHANGED
@@ -1,7 +1,22 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in aktion_test_rails.gemspec
4
- gemspec
3
+ gem 'rails', '~> 3.2.9'
4
+ gem 'activeadmin', '~> 0.5.0'
5
+ gem 'jquery-rails'
6
+
7
+ group :assets do
8
+ gem 'coffee-rails', '~> 3.2.1'
9
+ gem 'sass-rails', '~> 3.2.3'
10
+ end
5
11
 
6
- gem 'sqlite3', :platform => :ruby
12
+ platforms :ruby do
13
+ gem 'sqlite3'
14
+ end
7
15
 
16
+ platforms :jruby do
17
+ gem 'activerecord-jdbc-adapter'
18
+ gem 'activerecord-jdbcsqlite3-adapter'
19
+ gem 'jdbc-sqlite3'
20
+ end
21
+
22
+ gemspec
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # AktionTestRails
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/AktionLab/aktion_test_rails.png?branch=master)](https://travis-ci.org/AktionLab/aktion_test_rails)
4
+ [![Dependency Status](https://gemnasium.com/AktionLab/aktion_test_rails.png)](https://gemnasium.com/AktionLab/aktion_test_rails)
4
5
 
5
6
  Testing gem that includes a common set of testing gems, along with a suite of rspec matchers
6
7
 
@@ -20,7 +21,17 @@ Or install it yourself as:
20
21
 
21
22
  ## Usage
22
23
 
23
- TODO: Write usage instructions here
24
+ By default requiring aktion_test_rails will only setup some constants for lazy loading.
25
+
26
+ require 'aktion_test_rails/load'
27
+
28
+ Adding that line to your testing bootstrap (ie spec/test helper) will load up the full
29
+ testing environment. Most everything else can be lazy loaded on a per spec basis using
30
+ includes.
31
+
32
+ describe SomeClass do
33
+ include AktionTestRails::Support:Rails::ModelBuilder
34
+ end
24
35
 
25
36
  ## Contributing
26
37
 
data/Rakefile CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env rake
2
- require 'bundler/setup'
2
+ #require 'bundler/setup'
3
3
  require "bundler/gem_tasks"
4
4
  require 'rspec/core/rake_task'
5
- require 'appraisal'
6
5
 
7
6
  RSpec::Core::RakeTask.new do |t|
8
7
  t.pattern = "spec/**/*_spec.rb"
@@ -10,9 +9,4 @@ RSpec::Core::RakeTask.new do |t|
10
9
  t.verbose = false
11
10
  end
12
11
 
13
- desc 'Test the plugin under all supported Rails versions.'
14
- task :all => ["appraisal:cleanup", "appraisal:install"] do
15
- exec('rake appraisal spec')
16
- end
17
-
18
- task :default => [:all]
12
+ task :default => [:spec]
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = AktionTestRails::VERSION
17
17
 
18
- gem.add_dependency 'aktion_test', '0.0.2'
18
+ gem.add_dependency 'aktion_test', '~> 0.1.1'
19
19
  gem.add_dependency 'rspec-rails', '~> 2.12.0'
20
20
  gem.add_dependency 'factory_girl_rails', '~> 4.1.0'
21
21
  gem.add_dependency 'database_cleaner', '~> 0.9.1'
@@ -23,7 +23,4 @@ Gem::Specification.new do |gem|
23
23
  gem.add_dependency 'poltergeist', '~> 1.0.2'
24
24
  gem.add_dependency 'launchy', '~> 2.1.2'
25
25
  gem.add_dependency 'shoulda-matchers', '~> 1.4.1'
26
-
27
- gem.add_development_dependency 'appraisal', '~> 0.5.1'
28
- gem.add_development_dependency 'rails', '~> 3.0'
29
26
  end
@@ -0,0 +1,18 @@
1
+ require 'rspec-rails'
2
+ require 'rspec/rails'
3
+ require 'shoulda-matchers'
4
+ require 'factory_girl_rails'
5
+ require 'timecop'
6
+
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.mock_with :rspec
10
+
11
+ config.before :each do
12
+ Timecop.return if defined? Timecop
13
+ end
14
+
15
+ config.after :each do
16
+ Timecop.return if defined? Timecop
17
+ end
18
+ end
@@ -0,0 +1,93 @@
1
+ module AktionTestRails
2
+ module Matchers
3
+ module ActiveAdmin
4
+ module Flash
5
+ def have_flash(type = nil, message = nil)
6
+ type, message = nil, type if message.nil? && type.is_a?(String)
7
+ FlashMessageMatcher.new(type, message)
8
+ end
9
+
10
+ class FlashMessageMatcher < AktionTest::Matchers::Base
11
+ def initialize(type, message)
12
+ @type, @message = type, message
13
+ end
14
+
15
+ def matches?(page)
16
+ @page = page
17
+ has_flash? and has_flash_message?
18
+ end
19
+
20
+ def negative_failure_message
21
+ "Did not expect #{expectation}\n#{negative_problem}"
22
+ end
23
+
24
+ protected
25
+
26
+ def expectation
27
+ expect = "the page to have a flash"
28
+ unless @type.nil?
29
+ expect << " #{@type.to_s}"
30
+ end
31
+ unless @message.nil?
32
+ expect << " of `#{@message}'"
33
+ end
34
+ "#{expect}."
35
+ end
36
+
37
+ def problem
38
+ message = "\n"
39
+ unless has_flash?
40
+ if @page.has_selector? '.flash'
41
+ message << "Found a flash #{find_flash_type}.\n"
42
+ else
43
+ message << "No flash was found.\n"
44
+ end
45
+ end
46
+ unless has_flash_message?
47
+ if @page.has_selector? '.flash'
48
+ message << "expected: #{@message}\n got: #{flash_message}\n"
49
+ end
50
+ end
51
+ message
52
+ end
53
+
54
+ def negative_problem
55
+ message = ""
56
+ if @type.nil? && @message.nil?
57
+ message << "\nFound a flash #{find_flash_type} of `#{flash_message}'."
58
+ end
59
+ if !@type.nil? && has_flash?
60
+ message << "\nFlash is a #{find_flash_type}."
61
+ end
62
+ if !@message.nil? && has_flash_message?
63
+ message << "\nFlash message is `#{flash_message}'."
64
+ end
65
+ "#{message}\n"
66
+ end
67
+
68
+ private
69
+
70
+ def find_flash_type
71
+ @page.find('.flash')[:class].split(' ')[1].gsub('flash_','')
72
+ end
73
+
74
+ def has_flash?
75
+ @page.has_selector? flash_selector
76
+ end
77
+
78
+ def has_flash_message?
79
+ @message.nil? || flash_message == @message
80
+ end
81
+
82
+ def flash_message
83
+ @page.find('.flash').text
84
+ end
85
+
86
+ def flash_selector
87
+ @type.nil? ? '.flash' : ".flash_#{@type.to_s}"
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,50 @@
1
+ module AktionTestRails
2
+ module Matchers
3
+ # = Matchers for ActiveAdmin specs
4
+ #
5
+ # == Flash
6
+ #
7
+ # This method will test for the presence or absence of
8
+ # a flash message. The flash type and message are optional,
9
+ # if both are omitted then the matcher will simply look for
10
+ # a flash block. If the type is specified then it will also
11
+ # check that the flash type is a match.
12
+ #
13
+ # The matcher expects the subject to be a page from a request spec.
14
+ #
15
+ # describe 'AdminUser List' do
16
+ # describe 'destroy' do
17
+ # it 'display a flash message after deleting an admin user' do
18
+ # admin = AdminUser.create!(...)
19
+ # visit admin_admin_users_path
20
+ # within("tr#admin_user_#{admin.id}") { click_button 'Delete' }
21
+ # page.should have_flash(:notice, 'Admin deleted sucessfully.')
22
+ # # OR
23
+ # page.should have_flash('Admin deleted sucessfully.')
24
+ # # OR
25
+ # page.should have_flash(:notice)
26
+ # # OR
27
+ # page.should have_flash
28
+ # end
29
+ # end
30
+ # end
31
+ #
32
+ # Alternatively the opposing matchers also work as expected.
33
+ #
34
+ # # will fail if a flash exists
35
+ # should_not have_flash
36
+ # # will fail if a flash notice exists
37
+ # should_not have_flash(:notice)
38
+ # # will fail if a flash with the given message exists
39
+ # should_not have_flash('message')
40
+ # # will fail if a flash notice exists with the given message
41
+ # should_not have_flash(:notice, 'message')
42
+ module ActiveAdmin
43
+ extend ActiveSupport::Concern
44
+
45
+ included { include Flash }
46
+ end
47
+ end
48
+ end
49
+
50
+ ActiveSupport.run_load_hooks(:aktion_test_rails_matchers_active_admin)
@@ -0,0 +1,58 @@
1
+ module AktionTestRails
2
+ module Matchers
3
+ module FactoryGirl
4
+ module Validation
5
+ def have_valid_factory(factory_name)
6
+ ValidFactoryMatcher.new(factory_name)
7
+ end
8
+
9
+ class ValidFactoryMatcher < AktionTest::Matchers::Base
10
+ def initialize(factory_name)
11
+ @factory_name = factory_name
12
+ end
13
+
14
+ def matches?(subject)
15
+ factory_exists? && factory_creates_valid_record?
16
+ end
17
+
18
+ def expectation
19
+ ":#{@factory_name} to be a valid factory."
20
+ end
21
+
22
+ def problem
23
+ message = "\n"
24
+ if factory_exists?
25
+ if @record.errors.full_messages.any?
26
+ message << "Failed Validations:\n"
27
+ @record.errors.full_messages.each do |error|
28
+ message << " #{error}\n"
29
+ end
30
+ end
31
+ else
32
+ message << "No factory by the name :#{@factory_name} found\n"
33
+ end
34
+ message
35
+ end
36
+
37
+ def negative_problem
38
+ end
39
+
40
+ def description
41
+ "has a valid factory named :#{@factory_name}"
42
+ end
43
+
44
+ protected
45
+
46
+ def factory_exists?
47
+ ::FactoryGirl.factories.registered?(@factory_name)
48
+ end
49
+
50
+ def factory_creates_valid_record?
51
+ @record = ::FactoryGirl.build(@factory_name)
52
+ @record.valid?
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,5 +1,3 @@
1
- require 'aktion_test_rails/matchers/factory_girl/have_a_valid_factory'
2
-
3
1
  module AktionTestRails
4
2
  module Matchers
5
3
  # = Matchers for FactoryGirl factories
@@ -11,6 +9,13 @@ module AktionTestRails
11
9
  # end
12
10
  #
13
11
  module FactoryGirl
12
+ extend ActiveSupport::Concern
13
+
14
+ included do
15
+ include Validation
16
+ end
14
17
  end
15
18
  end
16
19
  end
20
+
21
+ ActiveSupport.run_load_hooks(:aktion_test_rails_matchers_active_admin)
@@ -0,0 +1,17 @@
1
+ module AktionTestRails
2
+ module Support
3
+ module ActiveAdmin
4
+ module Request
5
+ module SignIn
6
+ def sign_in_active_admin
7
+ @admin ||= FactoryGirl.create(:admin_user)
8
+ visit new_admin_user_session_path
9
+ fill_in 'Email', with: @admin.email
10
+ fill_in 'Password', with: 'password'
11
+ click_button 'Login'
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module AktionTestRails
2
+ module Support
3
+ module ActiveAdmin
4
+ module Request
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ include SignIn
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ ActiveSupport.run_load_hooks(:aktion_test_rails_support_active_admin_request)
16
+