effective_test_bot 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 348dcab0f742b0fc3c398a29924e03373b1c8899
4
- data.tar.gz: 3f4657ab5beea8f59ea201da177df6dbc9ff2d8c
3
+ metadata.gz: a39eb4dbe99bb9e9e190dcdea42b98217e899fbb
4
+ data.tar.gz: f3de18d8e670326b43977a17eaec8abc1bc9afc1
5
5
  SHA512:
6
- metadata.gz: 8d5fb505be70bf496edeae75bb397835db2385148a5b69cc87b903ec4af64e8c54e581afcf7c96af25e46d6e95b2c8be6dec9b7a729e937c43555c0633f9d7bc
7
- data.tar.gz: d54670db3513736069612105476f68b93c8e0a39cfcc36751a3804bb8f152dea7bdde713caa8b81e324b67b305ffa13beff64ba7622589df54b41cf5ee643649
6
+ metadata.gz: 6602fcc1c63846384499ff4c3d20109dc113f20ed8e3d18f804e7a960da289dd15ab3700f7de6c45ea186963af1397627d7062abba896008bc1a00882e0259b4
7
+ data.tar.gz: 430925ce013e377568e84a0e12295694adb9fe13355f7cb8129c0191f2c1b0db44f302af128d412c70f3310af2af111db8530cbf394e9cd40b8f535f8ff2da77
@@ -18,6 +18,11 @@ if Rails.env.test?
18
18
  # Silence skipped routes
19
19
  config.silence_skipped_routes = false
20
20
 
21
+ # Set the current user on a per test basis. You must have at least 1 user seeded.
22
+ # test is a String as per the except, only and TEST= test names
23
+ # proc = { |test| user = User.first; puts "#{test} #{user}"; user }
24
+ config.user = proc { |test| User.first }
25
+
21
26
  # Exits immediately if there is a test failure
22
27
  config.fail_fast = false
23
28
 
@@ -1,9 +1,11 @@
1
+ require 'effective_resources'
1
2
  require 'effective_test_bot/engine'
2
3
  require 'effective_test_bot/dsl'
3
4
  require 'effective_test_bot/middleware'
4
5
  require 'effective_test_bot/version'
5
6
 
6
7
  module EffectiveTestBot
8
+ mattr_accessor :user
7
9
  mattr_accessor :except
8
10
  mattr_accessor :only
9
11
  mattr_accessor :fail_fast
@@ -1,3 +1,3 @@
1
1
  module EffectiveTestBot
2
- VERSION = '0.6.2'.freeze
2
+ VERSION = '0.6.3'.freeze
3
3
  end
@@ -5,10 +5,6 @@ module TestBotable
5
5
  module ClassMethods
6
6
  TEST_BOT_TEST_PREFIXES = ['crud_test', 'devise_test', 'member_test', 'page_test', 'redirect_test', 'wizard_test']
7
7
 
8
- def _test_bot_user
9
- @test_bot_user
10
- end
11
-
12
8
  # Parses and validates lots of options
13
9
  # This is a big manual merge wherein we translate some DSL methods into one consistent Hash here
14
10
  # The output is what gets sent to each test and defined as lets
@@ -28,8 +24,6 @@ module TestBotable
28
24
 
29
25
  def normalize_test_bot_options!(options)
30
26
  raise 'expected options to be a Hash' unless options.kind_of?(Hash)
31
- raise 'expected key :user to be a User' unless (options[:user].kind_of?(User) || options[:user] == false)
32
- #raise 'expected key :current_test to be a String' unless options[:current_test].kind_of?(String)
33
27
 
34
28
  # Controller stuff
35
29
  options[:controller_namespace] ||= options[:namespace]
@@ -123,8 +117,20 @@ module TestBotable
123
117
 
124
118
  # Instance Methods
125
119
 
126
- def _test_bot_user
127
- @test_bot_user
120
+ def test_bot_user(test_name)
121
+ return @test_bot_user if @test_bot_user
122
+
123
+ unless EffectiveTestBot.user.kind_of?(Proc)
124
+ raise 'expected EffectiveTestBot.user to be a proc. Set config.user = Proc.new { |test| User.first }'
125
+ end
126
+
127
+ user = EffectiveTestBot.user.call(test_name)
128
+
129
+ unless user
130
+ raise "no user returned for #{test_name}. Please make sure the /config/initializers/effective_test_bot.rb config.user proc returns a user for this test."
131
+ end
132
+
133
+ user
128
134
  end
129
135
 
130
136
  # Using reverse_merge! in the dsl action_tests makes sure that the
@@ -18,7 +18,7 @@ module TestBotable
18
18
 
19
19
  # All this does is define a 'test_bot' method for each required action on this class
20
20
  # So that MiniTest will see the test functions and run them
21
- def crud_test(resource:, user: _test_bot_user(), label: nil, skip: {}, only: nil, except: nil, **options)
21
+ def crud_test(resource:, user: nil, label: nil, skip: {}, only: nil, except: nil, **options)
22
22
  # This skips paramaters is different than the initializer skips, which affect just the rake task
23
23
 
24
24
  # These are specificially for the DSL
@@ -28,7 +28,7 @@ module TestBotable
28
28
  current_crud_tests = crud_tests_to_define(only, except)
29
29
 
30
30
  begin
31
- normalize_test_bot_options!(options.merge!(resource: resource, user: user, current_crud_tests: current_crud_tests))
31
+ normalize_test_bot_options!(options.merge!(resource: resource, current_crud_tests: current_crud_tests))
32
32
  rescue => e
33
33
  raise "Error: #{e.message}. Expected usage: crud_test(resource: (Post || Post.new), user: User.first, only: [:new, :create], skip: {create_invalid: [:path]})"
34
34
  end
@@ -78,7 +78,9 @@ module TestBotable
78
78
  #
79
79
  # If obj is a Hash {:resource => ...} just skip over parsing options
80
80
  # And assume it's already been done (by the ClassMethod crud_test)
81
- def crud_action_test(test:, resource:, user: _test_bot_user(), **options)
81
+ def crud_action_test(test:, resource:, user: nil, **options)
82
+ user ||= test_bot_user(options[:current_test])
83
+
82
84
  begin
83
85
  assign_test_bot_lets!(options.reverse_merge!(resource: resource, user: user))
84
86
  rescue => e
@@ -16,7 +16,7 @@ module TestBotable
16
16
  extend ActiveSupport::Concern
17
17
 
18
18
  module ClassMethods
19
- def member_test(controller:, action:, user: _test_bot_user(), member: nil, label: nil, **options)
19
+ def member_test(controller:, action:, user: nil, member: nil, label: nil, **options)
20
20
  options[:current_test] = label || "#{controller}##{action}"
21
21
  return if EffectiveTestBot.skip?(options[:current_test])
22
22
 
@@ -28,7 +28,9 @@ module TestBotable
28
28
  end
29
29
 
30
30
  # Instance Methods - Call me from within a test
31
- def member_action_test(controller:, action:, user: _test_bot_user(), member:, **options)
31
+ def member_action_test(controller:, action:, user: nil, member:, **options)
32
+ user ||= test_bot_user(options[:current_test])
33
+
32
34
  begin
33
35
  assign_test_bot_lets!(options.reverse_merge!(resource: controller, action: action, user: user, member: member))
34
36
  rescue => e
@@ -15,7 +15,7 @@ module TestBotable
15
15
 
16
16
  module ClassMethods
17
17
 
18
- def page_test(path:, user: _test_bot_user(), label: nil, **options)
18
+ def page_test(path:, user: nil, label: nil, **options)
19
19
  options[:current_test] = label || path.to_s
20
20
  return if EffectiveTestBot.skip?(options[:current_test])
21
21
 
@@ -27,7 +27,9 @@ module TestBotable
27
27
  end
28
28
 
29
29
  # Instance Methods - Call me from within a test
30
- def page_action_test(path:, user: _test_bot_user(), **options)
30
+ def page_action_test(path:, user: nil, **options)
31
+ user ||= test_bot_user(options[:current_test])
32
+
31
33
  begin
32
34
  assign_test_bot_lets!(options.reverse_merge!(user: user, page_path: path))
33
35
  rescue => e
@@ -14,7 +14,7 @@ module TestBotable
14
14
 
15
15
  module ClassMethods
16
16
 
17
- def redirect_test(from:, to:, user: _test_bot_user(), label: nil, **options)
17
+ def redirect_test(from:, to:, user: nil, label: nil, **options)
18
18
  options[:current_test] = label || "#{from} to #{to}"
19
19
  return if EffectiveTestBot.skip?(options[:current_test])
20
20
 
@@ -25,7 +25,9 @@ module TestBotable
25
25
  end
26
26
 
27
27
  # Instance Methods - Call me from within a test
28
- def redirect_action_test(from:, to:, user: _test_bot_user(), **options)
28
+ def redirect_action_test(from:, to:, user: nil, **options)
29
+ user ||= test_bot_user(options[:current_test])
30
+
29
31
  begin
30
32
  assign_test_bot_lets!(options.reverse_merge!(from: from, to: to, user: user))
31
33
  rescue => e
@@ -19,7 +19,7 @@ module TestBotable
19
19
 
20
20
  module ClassMethods
21
21
 
22
- def wizard_test(from:, to: nil, user: _test_bot_user(), label: nil, **options)
22
+ def wizard_test(from:, to: nil, user: nil, label: nil, **options)
23
23
  options[:current_test] = label || (to.present? ? "#{from} to #{to}" : from.to_s)
24
24
  return if EffectiveTestBot.skip?(options[:current_test])
25
25
 
@@ -31,7 +31,9 @@ module TestBotable
31
31
  end
32
32
 
33
33
  # Instance Methods - Call me from within a test
34
- def wizard_action_test(from:, to: nil, user: _test_bot_user(), **options)
34
+ def wizard_action_test(from:, to: nil, user: nil, **options)
35
+ user ||= test_bot_user(options[:current_test])
36
+
35
37
  begin
36
38
  assign_test_bot_lets!(options.reverse_merge!(from: from, to: to, user: user))
37
39
  rescue => e
@@ -72,6 +72,8 @@ module EffectiveTestBotFormFiller
72
72
  case [field.tag_name, field['type']].compact.join('_')
73
73
  when 'input_text', 'input_email', 'input_password', 'input_tel', 'input_number', 'input_checkbox', 'input_radio', 'input_url', 'input_color'
74
74
  field.set(value_for_field(field, fills))
75
+
76
+ close_effective_date_time_picker(field) if field['class'].to_s.include?('effective_date')
75
77
  when 'textarea'
76
78
  value = value_for_field(field, fills)
77
79
  ckeditor_text_area?(field) ? fill_ckeditor_text_area(field, value) : field.set(value)
@@ -11,8 +11,6 @@ module TestBot
11
11
 
12
12
  # Go through every route, and run an appropriate test suite on it
13
13
  def initialize_tests
14
- @test_bot_user = User.first
15
-
16
14
  routes = Rails.application.routes.routes.to_a
17
15
  seen_actions = Hash.new([]) # {posts: ['new', 'edit'], events: ['new', 'edit', 'show']}
18
16
 
@@ -127,20 +125,8 @@ module TestBot
127
125
  return :none unless route.defaults[:controller] && route.defaults[:action]
128
126
 
129
127
  @_controller_instances ||= {}
130
- @_controller_instances[route.defaults[:controller]] ||= build_controller_instance(route)
131
- end
132
-
133
- def build_controller_instance(route)
134
- # Find the correct route.app that links to the controller
135
- # If there is a routing constraint, we have to traverse the route.app linked list to find the route with a controller
136
- route_app = route
137
- route_app = route_app.app while (route_app.respond_to?(:app) && route_app != route_app.app)
138
-
139
- return :none unless route_app.respond_to?(:controller)
140
-
141
- (route_app.controller(route.defaults).new() rescue :none)
128
+ @_controller_instances[route.defaults[:controller]] ||= (Effective::Resource.new(route).controller_klass.new() rescue :none)
142
129
  end
143
-
144
130
  end
145
131
 
146
132
  initialize_tests
@@ -48,7 +48,7 @@ module CrudTest
48
48
  def test_bot_create_invalid_test
49
49
  sign_in(user) and visit(new_resource_path)
50
50
 
51
- before = { count: resource_class.count }
51
+ before = { count: (resource_class.count if resource_class.respond_to?(:count)) }
52
52
 
53
53
  assert_form("form#new_#{resource_name}") unless test_bot_skip?(:form)
54
54
 
@@ -59,14 +59,14 @@ module CrudTest
59
59
 
60
60
  save_test_bot_screenshot
61
61
 
62
- after = { count: resource_class.count }
62
+ after = { count: (resource_class.count if resource_class.respond_to?(:count)) }
63
63
 
64
64
  assert_page_normal
65
65
 
66
66
  assert_assigns(resource_name) unless test_bot_skip?(:assigns)
67
67
  assert_assigns_errors(resource_name) unless test_bot_skip?(:assigns_errors)
68
68
 
69
- assert_equal before[:count], after[:count], "Expected #{resource_class}.count to be unchanged"
69
+ assert_equal(before[:count], after[:count], "Expected #{resource_class}.count to be unchanged") if resource_class.respond_to?(:count)
70
70
  assert_equal(resources_path, page.current_path, "(path) Expected current_path to match resource #create path #{resources_path}") unless test_bot_skip?(:path)
71
71
 
72
72
  assert_flash(:danger) unless test_bot_skip?(:flash)
@@ -76,7 +76,7 @@ module CrudTest
76
76
  sign_in(user) and visit(new_resource_path)
77
77
  save_test_bot_screenshot
78
78
 
79
- before = { count: resource_class.count, path: page.current_path }
79
+ before = { count: (resource_class.count if resource_class.respond_to?(:count)), path: page.current_path }
80
80
 
81
81
  assert_form("form#new_#{resource_name}") unless test_bot_skip?(:form)
82
82
 
@@ -87,7 +87,7 @@ module CrudTest
87
87
 
88
88
  save_test_bot_screenshot
89
89
 
90
- after = { count: resource_class.count, path: page.current_path }
90
+ after = { count: (resource_class.count if resource_class.respond_to?(:count)), path: page.current_path }
91
91
 
92
92
  assert_page_normal
93
93
  assert_no_flash_errors unless test_bot_skip?(:no_flash_errors)
@@ -97,7 +97,7 @@ module CrudTest
97
97
  assert_assigns(resource_name) if (after[:path].include?('/edit/') && !test_bot_skip?(:assigns))
98
98
  assert_no_assigns_errors(resource_name) unless test_bot_skip?(:no_assigns_errors)
99
99
 
100
- refute_equal before[:count], after[:count], "Expected fill_form to create a #{resource_class} object"
100
+ refute_equal(before[:count], after[:count], "Expected fill_form to create a #{resource_class} object") if resource_class.respond_to?(:count)
101
101
  refute_equal(before[:path], after[:path], "(path) Expected unique before and after paths") unless test_bot_skip?(:path)
102
102
  end
103
103
 
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_test_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-05 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: effective_resources
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="