aktion_test_rails 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,13 @@
1
+ # v0.3.0
2
+
3
+ * Update modules to use new spec helper interface
4
+
5
+ # v0.2.1
6
+
7
+ * Update matchers to work with new base matcher
8
+ * Upgrade to aktion test 0.2.x
9
+ * Create modules to use with new spec helper loader
10
+
1
11
  # v0.2.0
2
12
 
3
13
  * ActiveAdmin request spec sign in support
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # AktionTestRails
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/AktionLab/aktion_test_rails.png)](https://codeclimate.com/github/AktionLab/aktion_test_rails)
3
4
  [![Build Status](https://secure.travis-ci.org/AktionLab/aktion_test_rails.png?branch=master)](https://travis-ci.org/AktionLab/aktion_test_rails)
4
5
  [![Dependency Status](https://gemnasium.com/AktionLab/aktion_test_rails.png)](https://gemnasium.com/AktionLab/aktion_test_rails)
5
6
 
@@ -15,12 +15,13 @@ 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.1.1'
19
- gem.add_dependency 'rspec-rails', '~> 2.12.0'
20
- gem.add_dependency 'factory_girl_rails', '~> 4.1.0'
21
- gem.add_dependency 'database_cleaner', '~> 0.9.1'
22
- gem.add_dependency 'capybara', '~> 1.1.3'
23
- gem.add_dependency 'poltergeist', '~> 1.0.2'
24
- gem.add_dependency 'launchy', '~> 2.1.2'
25
- gem.add_dependency 'shoulda-matchers', '~> 1.4.1'
18
+ gem.add_dependency 'activesupport', '~> 3.2.11'
19
+ gem.add_dependency 'aktion_test', '~> 0.3.0'
20
+ gem.add_dependency 'rspec-rails', '~> 2.12.0'
21
+ gem.add_dependency 'factory_girl_rails', '~> 4.2.0'
22
+ gem.add_dependency 'database_cleaner', '~> 0.9.1'
23
+ gem.add_dependency 'capybara', '~> 1.1.3'
24
+ gem.add_dependency 'poltergeist', '~> 1.0.2'
25
+ gem.add_dependency 'launchy', '~> 2.1.2'
26
+ gem.add_dependency 'shoulda-matchers', '~> 1.4.1'
26
27
  end
@@ -0,0 +1,11 @@
1
+ module AktionTest
2
+ module Module
3
+ class Rails < Base
4
+ def prepare
5
+ require options[:path]
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ ActiveSupport.run_load_hooks :aktion_test_module_rails
@@ -0,0 +1,12 @@
1
+ module AktionTest
2
+ module Module
3
+ class Rails
4
+ class AktionTest < Base
5
+ def initialize(spec, options={})
6
+ spec.use ::AktionTest::Module::AktionTest
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ module AktionTest
2
+ module Module
3
+ class Rails
4
+ class Capybara < Base
5
+ def prepare
6
+ require 'capybara/rails'
7
+ require 'capybara/rspec'
8
+ require 'capybara/poltergeist'
9
+ end
10
+
11
+ def configure
12
+ ::Capybara.javascript_driver = :poltergeist
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ ActiveSupport.on_load(:active_recod) do
20
+ class ActiveRecord::Base
21
+ mattr_accessor :shared_connection
22
+ @@shared_connection = nil
23
+
24
+ def self.connection
25
+ @@shared_connection ||= retrieve_connection
26
+ end
27
+ end
28
+
29
+ ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
30
+ end
@@ -0,0 +1,21 @@
1
+ module AktionTest
2
+ module Module
3
+ class Rails
4
+ class FactoryGirl < Base
5
+ def initialize(spec, options={})
6
+ super
7
+ end
8
+
9
+ def prepare
10
+ require 'factory_girl_rails'
11
+ end
12
+
13
+ def configure
14
+ rspec.include ::FactoryGirl::Syntax::Methods
15
+ rspec.include AktionTestRails::Matchers::FactoryGirl, type: :model
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,23 @@
1
+ module AktionTest
2
+ module Module
3
+ class Rails
4
+ class RSpec < Base
5
+ def initialize(spec, options={})
6
+ spec.use ::AktionTest::Module::RSpec
7
+ super
8
+ end
9
+
10
+ def prepare
11
+ require 'rspec/rails'
12
+ end
13
+
14
+ def configure
15
+ rspec.fixture_path = "#{::Rails.root}/spec/fixtures"
16
+ rspec.use_transactional_fixtures = true
17
+ rspec.infer_base_class_for_anonymous_controllers = false
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,12 @@
1
+ module AktionTest
2
+ module Module
3
+ class Rails
4
+ class ShouldaMatchers < Base
5
+ def prepare
6
+ require 'shoulda-matchers'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,13 @@
1
+ module AktionTest
2
+ module Module
3
+ class Rails
4
+ class Simplecov < Base
5
+ def initialize(spec, options={})
6
+ require 'simplecov'
7
+ ::SimpleCov.start 'rails'
8
+ super
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,15 +1,29 @@
1
- require 'faker'
2
1
  require 'aktion_test'
3
2
  require "aktion_test_rails/version"
4
3
 
5
- require 'active_support/dependencies/autoload'
6
- require 'active_support/concern'
7
- require 'active_support/lazy_load_hooks'
4
+ module AktionTest
5
+ module Module
6
+ extend ActiveSupport::Autoload
7
+
8
+ autoload :Rails
9
+
10
+ ActiveSupport.on_load(:aktion_test_module_rails) do
11
+ class Rails
12
+ extend ActiveSupport::Autoload
13
+
14
+ autoload :AktionTest
15
+ autoload :Capybara
16
+ autoload :FactoryGirl
17
+ autoload :RSpec, 'aktion_test/module/rails/rspec'
18
+ autoload :ShouldaMatchers
19
+ autoload :Simplecov
20
+ end
21
+ end
22
+ end
23
+ end
8
24
 
9
25
  module AktionTestRails
10
26
  extend ActiveSupport::Autoload
11
-
12
- autoload :ModelBuilder
13
27
 
14
28
  module Support
15
29
  module Capybara
@@ -4,24 +4,19 @@ module AktionTestRails
4
4
  module Flash
5
5
  def have_flash(type = nil, message = nil)
6
6
  type, message = nil, type if message.nil? && type.is_a?(String)
7
- FlashMessageMatcher.new(type, message)
7
+ Matcher.new(type, message)
8
8
  end
9
9
 
10
- class FlashMessageMatcher < AktionTest::Matchers::Base
10
+ class Matcher < AktionTest::Matchers::Base
11
11
  def initialize(type, message)
12
12
  @type, @message = type, message
13
13
  end
14
14
 
15
- def matches?(page)
16
- @page = page
15
+ protected
16
+
17
+ def perform_match!
17
18
  has_flash? and has_flash_message?
18
19
  end
19
-
20
- def negative_failure_message
21
- "Did not expect #{expectation}\n#{negative_problem}"
22
- end
23
-
24
- protected
25
20
 
26
21
  def expectation
27
22
  expect = "the page to have a flash"
@@ -34,24 +29,24 @@ module AktionTestRails
34
29
  "#{expect}."
35
30
  end
36
31
 
37
- def problem
32
+ def problems_for_should
38
33
  message = "\n"
39
34
  unless has_flash?
40
- if @page.has_selector? '.flash'
35
+ if @subject.has_selector? '.flash'
41
36
  message << "Found a flash #{find_flash_type}.\n"
42
37
  else
43
38
  message << "No flash was found.\n"
44
39
  end
45
40
  end
46
41
  unless has_flash_message?
47
- if @page.has_selector? '.flash'
48
- message << "expected: #{@message}\n got: #{flash_message}\n"
42
+ if @subject.has_selector? '.flash'
43
+ message << "expected: #{@message}\n got: #{flash_message}"
49
44
  end
50
45
  end
51
- message
46
+ message.chomp
52
47
  end
53
48
 
54
- def negative_problem
49
+ def problems_for_should_not
55
50
  message = ""
56
51
  if @type.nil? && @message.nil?
57
52
  message << "\nFound a flash #{find_flash_type} of `#{flash_message}'."
@@ -62,17 +57,17 @@ module AktionTestRails
62
57
  if !@message.nil? && has_flash_message?
63
58
  message << "\nFlash message is `#{flash_message}'."
64
59
  end
65
- "#{message}\n"
60
+ message
66
61
  end
67
62
 
68
63
  private
69
64
 
70
65
  def find_flash_type
71
- @page.find('.flash')[:class].split(' ')[1].gsub('flash_','')
66
+ @subject.find('.flash')[:class].split(' ')[1].gsub('flash_','')
72
67
  end
73
68
 
74
69
  def has_flash?
75
- @page.has_selector? flash_selector
70
+ @subject.has_selector? flash_selector
76
71
  end
77
72
 
78
73
  def has_flash_message?
@@ -80,7 +75,7 @@ module AktionTestRails
80
75
  end
81
76
 
82
77
  def flash_message
83
- @page.find('.flash').text
78
+ @subject.find('.flash').text
84
79
  end
85
80
 
86
81
  def flash_selector
@@ -11,8 +11,8 @@ module AktionTestRails
11
11
  module FactoryGirl
12
12
  extend ActiveSupport::Concern
13
13
 
14
- included do
15
- include Validation
14
+ included do |base|
15
+ base.send :include, Validation
16
16
  end
17
17
  end
18
18
  end
@@ -3,23 +3,25 @@ module AktionTestRails
3
3
  module FactoryGirl
4
4
  module Validation
5
5
  def have_valid_factory(factory_name)
6
- ValidFactoryMatcher.new(factory_name)
6
+ Matcher.new(factory_name)
7
7
  end
8
8
 
9
- class ValidFactoryMatcher < AktionTest::Matchers::Base
9
+ class Matcher < AktionTest::Matchers::Base
10
10
  def initialize(factory_name)
11
11
  @factory_name = factory_name
12
12
  end
13
13
 
14
- def matches?(subject)
15
- factory_exists? && factory_creates_valid_record?
14
+ def description
15
+ "has a valid factory named :#{@factory_name}"
16
16
  end
17
17
 
18
+ protected
19
+
18
20
  def expectation
19
21
  ":#{@factory_name} to be a valid factory."
20
22
  end
21
23
 
22
- def problem
24
+ def problems_for_should
23
25
  message = "\n"
24
26
  if factory_exists?
25
27
  if @record.errors.full_messages.any?
@@ -31,18 +33,16 @@ module AktionTestRails
31
33
  else
32
34
  message << "No factory by the name :#{@factory_name} found\n"
33
35
  end
34
- message
36
+ message.chomp
35
37
  end
36
38
 
37
- def negative_problem
39
+ def problems_for_should_not
38
40
  end
39
41
 
40
- def description
41
- "has a valid factory named :#{@factory_name}"
42
+ def perform_match!
43
+ factory_exists? && factory_creates_valid_record?
42
44
  end
43
45
 
44
- protected
45
-
46
46
  def factory_exists?
47
47
  ::FactoryGirl.factories.registered?(@factory_name)
48
48
  end
@@ -1,3 +1,3 @@
1
1
  module AktionTestRails
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,5 +1,4 @@
1
- require 'spec_base'
2
- require 'spec_active_record'
1
+ require 'spec_helper'
3
2
 
4
3
  describe AktionTestRails::Support::Rails::ModelBuilder do
5
4
  include described_class
@@ -1,4 +1,4 @@
1
- require 'spec_base'
1
+ require 'spec_helper'
2
2
 
3
3
  describe AktionTestRails::Matchers::ActiveAdmin::Flash do
4
4
  include described_class
@@ -1,6 +1,4 @@
1
- require 'spec_base'
2
- require 'spec_active_record'
3
- require 'factory_girl_rails'
1
+ require 'spec_helper'
4
2
 
5
3
  describe AktionTestRails::Matchers::FactoryGirl::Validation do
6
4
  include described_class
@@ -1,10 +1,9 @@
1
- require 'spec_base'
2
- require 'spec_rails'
1
+ require 'spec_helper'
3
2
 
4
3
  describe AktionTestRails::Support::ActiveAdmin::Request::SignIn do
5
4
  include described_class
6
5
 
7
- before(:each) do
6
+ before(:all) do
8
7
  unless FactoryGirl.factories.registered?(:admin_user)
9
8
  FactoryGirl.define do
10
9
  factory :admin_user do
@@ -0,0 +1,30 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'aktion_test_rails'
4
+ ENV['RAILS_ENV'] = 'test'
5
+
6
+ TESTAPP_ROOT = File.join(File.dirname(__FILE__), 'rails_app')
7
+ I18n.load_path << File.join(TESTAPP_ROOT, 'config/locales/en.yml')
8
+ I18n.load_path << File.join(TESTAPP_ROOT, 'config/locales/devise.en.yml')
9
+
10
+ require 'activeadmin'
11
+
12
+ require 'simplecov'
13
+ SimpleCov.start do
14
+ add_filter '/spec/'
15
+ add_group 'Modules', 'lib/aktion_test/module'
16
+ add_group 'Matchers', 'lib/aktion_test_rails/matchers'
17
+ add_group 'Support', 'lib/aktion_test_rails/support'
18
+ end
19
+
20
+ AktionTest::SpecHelper.build do
21
+ use :Timecop, :Faker
22
+ use :Rails, :path => File.expand_path('../rails_app/config/environment', __FILE__)
23
+
24
+ scope 'Rails' do
25
+ use :RSpec, :AktionTest, :ShouldaMatchers, :FactoryGirl, :Capybara
26
+ end
27
+ end
28
+
29
+ ActiveRecord::Migration.verbose = false
30
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aktion_test_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-14 00:00:00.000000000 Z
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.11
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.11
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: aktion_test
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -18,7 +34,7 @@ dependencies:
18
34
  requirements:
19
35
  - - ~>
20
36
  - !ruby/object:Gem::Version
21
- version: 0.1.1
37
+ version: 0.3.0
22
38
  type: :runtime
23
39
  prerelease: false
24
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +42,7 @@ dependencies:
26
42
  requirements:
27
43
  - - ~>
28
44
  - !ruby/object:Gem::Version
29
- version: 0.1.1
45
+ version: 0.3.0
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rspec-rails
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +66,7 @@ dependencies:
50
66
  requirements:
51
67
  - - ~>
52
68
  - !ruby/object:Gem::Version
53
- version: 4.1.0
69
+ version: 4.2.0
54
70
  type: :runtime
55
71
  prerelease: false
56
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +74,7 @@ dependencies:
58
74
  requirements:
59
75
  - - ~>
60
76
  - !ruby/object:Gem::Version
61
- version: 4.1.0
77
+ version: 4.2.0
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: database_cleaner
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -157,8 +173,14 @@ files:
157
173
  - README.md
158
174
  - Rakefile
159
175
  - aktion_test_rails.gemspec
176
+ - lib/aktion_test/module/rails.rb
177
+ - lib/aktion_test/module/rails/aktion_test.rb
178
+ - lib/aktion_test/module/rails/capybara.rb
179
+ - lib/aktion_test/module/rails/factory_girl.rb
180
+ - lib/aktion_test/module/rails/rspec.rb
181
+ - lib/aktion_test/module/rails/shoulda_matchers.rb
182
+ - lib/aktion_test/module/rails/simplecov.rb
160
183
  - lib/aktion_test_rails.rb
161
- - lib/aktion_test_rails/load.rb
162
184
  - lib/aktion_test_rails/matchers/active_admin.rb
163
185
  - lib/aktion_test_rails/matchers/active_admin/flash.rb
164
186
  - lib/aktion_test_rails/matchers/factory_girl.rb
@@ -207,9 +229,7 @@ files:
207
229
  - spec/rails_app/public/robots.txt
208
230
  - spec/rails_app/script/rails
209
231
  - spec/requests/active_admin/sign_in_spec.rb
210
- - spec/spec_active_record.rb
211
- - spec/spec_base.rb
212
- - spec/spec_rails.rb
232
+ - spec/spec_helper.rb
213
233
  homepage: http://aktionlab.com
214
234
  licenses: []
215
235
  post_install_message:
@@ -274,6 +294,4 @@ test_files:
274
294
  - spec/rails_app/public/robots.txt
275
295
  - spec/rails_app/script/rails
276
296
  - spec/requests/active_admin/sign_in_spec.rb
277
- - spec/spec_active_record.rb
278
- - spec/spec_base.rb
279
- - spec/spec_rails.rb
297
+ - spec/spec_helper.rb
@@ -1,18 +0,0 @@
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
@@ -1,13 +0,0 @@
1
- require 'active_record'
2
- require 'rspec/rails/adapters'
3
- require 'rspec/rails/fixture_support'
4
-
5
- if RUBY_PLATFORM =~ /java/
6
- ActiveRecord::Base.establish_connection(adapter: 'jdbcsqlite3', database: 'tmp/test.sqlite3')
7
- else
8
- ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'tmp/test.sqlite3')
9
- end
10
-
11
- RSpec.configure do |config|
12
- config.use_transactional_fixtures = true
13
- end
@@ -1,28 +0,0 @@
1
- ENV['RAILS_ENV'] = 'test'
2
-
3
- require 'simplecov'
4
-
5
- SimpleCov.start do
6
- add_filter '/tmp/'
7
- add_filter '/spec/'
8
- add_filter '/lib/aktion_test_rails/matchers/factory_girl.rb'
9
- add_filter '/lib/aktion_test_rails/matchers/active_admin.rb'
10
- add_filter '/lib/aktion_test_rails/support/active_admin/request.rb'
11
- add_filter '/lib/aktion_test_rails/rails.rb'
12
- add_filter '/lib/aktion_test_rails.rb'
13
- minimum_coverage 100
14
- end
15
-
16
- FileUtils.mkdir('tmp') unless Dir.exists?('tmp')
17
-
18
- require 'aktion_test_rails'
19
- require 'capybara'
20
- require 'active_support/core_ext/string'
21
-
22
- Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each{|file| require file}
23
-
24
- RSpec.configure do |config|
25
- config.treat_symbols_as_metadata_keys_with_true_values = true
26
- config.run_all_when_everything_filtered = true
27
- config.order = 'random'
28
- end
@@ -1,18 +0,0 @@
1
- TESTAPP_ROOT = File.join(File.dirname(__FILE__), 'rails_app')
2
- PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
3
-
4
- $:.unshift File.dirname(__FILE__)
5
- $:.unshift File.join(PROJECT_ROOT, 'lib')
6
-
7
- require "rails_app/config/environment"
8
- require 'aktion_test_rails/rails'
9
-
10
- I18n.load_path << File.join(TESTAPP_ROOT, 'config/locales/en.yml')
11
- I18n.load_path << File.join(TESTAPP_ROOT, 'config/locales/devise.en.yml')
12
-
13
- ActiveRecord::Migration.verbose = false
14
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
15
-
16
- RSpec.configure do |config|
17
- config.use_transactional_fixtures = true
18
- end