portal_module 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/Gemfile +13 -0
- data/Guardfile +24 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +240 -0
- data/Rakefile +101 -0
- data/bin/portal_module +10 -0
- data/lib/portal_module/assertable.rb +37 -0
- data/lib/portal_module/cli.rb +35 -0
- data/lib/portal_module/client.rb +110 -0
- data/lib/portal_module/command/client_access.rb +41 -0
- data/lib/portal_module/command/config.rb +323 -0
- data/lib/portal_module/command/dts.rb +70 -0
- data/lib/portal_module/command/loan_entry.rb +66 -0
- data/lib/portal_module/command.rb +16 -0
- data/lib/portal_module/config_helper.rb +32 -0
- data/lib/portal_module/dts.rb +99 -0
- data/lib/portal_module/loan_entry.rb +101 -0
- data/lib/portal_module/page_factory.rb +27 -0
- data/lib/portal_module/pages/data_transformation_page.rb +84 -0
- data/lib/portal_module/pages/login_page.rb +73 -0
- data/lib/portal_module/pages/prequal_setup_page.rb +77 -0
- data/lib/portal_module/pages.rb +90 -0
- data/lib/portal_module/rake/dts_tasks.rb +166 -0
- data/lib/portal_module/rake/loan_entry_tasks.rb +166 -0
- data/lib/portal_module/rake.rb +16 -0
- data/lib/portal_module/version.rb +3 -0
- data/lib/portal_module.rb +251 -0
- data/portal_module.gemspec +33 -0
- data/spec/data/dts_import.xml +1 -0
- data/spec/data/le_import.xml +1 -0
- data/spec/lib/portal_module/cli_spec.rb +35 -0
- data/spec/lib/portal_module/client_spec.rb +126 -0
- data/spec/lib/portal_module/command/config_spec.rb +474 -0
- data/spec/lib/portal_module/command/dts_spec.rb +98 -0
- data/spec/lib/portal_module/command/loan_entry_spec.rb +98 -0
- data/spec/lib/portal_module/dts_spec.rb +145 -0
- data/spec/lib/portal_module/loan_entry_spec.rb +113 -0
- data/spec/lib/portal_module_spec.rb +175 -0
- data/spec/spec_helper.rb +52 -0
- data/spec/support/asserts.rb +10 -0
- data/spec/support/dirs.rb +53 -0
- data/spec/support/helpers.rb +44 -0
- data/spec/support/mocks.rb +106 -0
- metadata +247 -0
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PortalModule do
|
4
|
+
|
5
|
+
before do
|
6
|
+
# Reset config to a known state.
|
7
|
+
PortalModule.configuration.reset
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:config) do
|
11
|
+
PortalModule.configure
|
12
|
+
PortalModule.configuration
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".configure" do
|
16
|
+
context "no arguments provided" do
|
17
|
+
|
18
|
+
it "creates configuration" do
|
19
|
+
PortalModule.configure
|
20
|
+
expect( PortalModule.configuration ).to_not be nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ".find_config_path" do
|
27
|
+
|
28
|
+
it "returns nil if config not found" do
|
29
|
+
with_target_dir('config/location') do
|
30
|
+
expect( PortalModule.find_config_path ).to be nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns path if config found" do
|
35
|
+
with_target_dir('config/location') do |target_dir|
|
36
|
+
target = target_dir + '.portal_module'
|
37
|
+
|
38
|
+
# Create a config file to find
|
39
|
+
PortalModule.save_configuration target
|
40
|
+
|
41
|
+
actual = nil
|
42
|
+
|
43
|
+
# Find the file in a parent directory
|
44
|
+
with_target_dir(target_dir + 'some/nested/location') do
|
45
|
+
actual = PortalModule.find_config_path
|
46
|
+
end
|
47
|
+
|
48
|
+
expect( actual.to_s ).to eq target.expand_path.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe ".save_configuration" do
|
54
|
+
|
55
|
+
context "filename argument provided" do
|
56
|
+
|
57
|
+
it "creates a file" do
|
58
|
+
with_target_dir('config/location') do |target|
|
59
|
+
target = target + '.portal_module'
|
60
|
+
|
61
|
+
PortalModule.save_configuration target
|
62
|
+
|
63
|
+
expect( target.exist? ).to be true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "no filename argument provided" do
|
69
|
+
|
70
|
+
context "config file doesn't exist in any parent directory" do
|
71
|
+
|
72
|
+
it "creates a file in current dir" do
|
73
|
+
with_target_dir('config/location') do |target|
|
74
|
+
PortalModule.save_configuration
|
75
|
+
|
76
|
+
target = target + '.portal_module'
|
77
|
+
|
78
|
+
expect( target.exist? ).to be true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "config file exists in a parent directory" do
|
84
|
+
|
85
|
+
it "updates file in parent directory" do
|
86
|
+
with_target_dir('config/location') do |actual_location|
|
87
|
+
actual = actual_location + '.portal_module'
|
88
|
+
|
89
|
+
# Save the default configuration in a known location
|
90
|
+
PortalModule.configuration.reset
|
91
|
+
PortalModule.save_configuration actual
|
92
|
+
|
93
|
+
# Change the configuration
|
94
|
+
PortalModule.configure do |c|
|
95
|
+
c.browser_timeout = 1800
|
96
|
+
end
|
97
|
+
|
98
|
+
with_target_dir(actual_location + 'some/nested/location') do |start_dir|
|
99
|
+
PortalModule.save_configuration
|
100
|
+
end
|
101
|
+
|
102
|
+
expect( File.readlines(actual) ).to include "browser_timeout: 1800\n"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe ".load_configuration" do
|
110
|
+
|
111
|
+
context "filename argument provided" do
|
112
|
+
context "config file doesn't exist" do
|
113
|
+
it "returns false" do
|
114
|
+
expect( PortalModule.load_configuration('not/a/real/path') ).to eq false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "config file exists" do
|
119
|
+
it "loads the configuration" do
|
120
|
+
with_target_dir('config/load') do |actual_location|
|
121
|
+
actual = actual_location + '.portal_module'
|
122
|
+
|
123
|
+
# Change the configuration
|
124
|
+
PortalModule.configure do |c|
|
125
|
+
c.browser_timeout = 900
|
126
|
+
end
|
127
|
+
|
128
|
+
# Save the configuration in a known location
|
129
|
+
PortalModule.save_configuration actual
|
130
|
+
|
131
|
+
# Reset the config (clean the slate)
|
132
|
+
PortalModule.configuration.reset
|
133
|
+
|
134
|
+
PortalModule.load_configuration actual
|
135
|
+
expect( PortalModule.configuration.browser_timeout ).to eq 900
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "no filename argument provided" do
|
142
|
+
context "config file doesn't exist in any parent directory" do
|
143
|
+
it "returns false" do
|
144
|
+
expect( PortalModule.load_configuration ).to eq false
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "config file exists in a parent directory" do
|
149
|
+
it "loads the configuration" do
|
150
|
+
with_target_dir('config/load') do |actual_location|
|
151
|
+
actual = actual_location + '.portal_module'
|
152
|
+
|
153
|
+
# Change the configuration
|
154
|
+
PortalModule.configure do |c|
|
155
|
+
c.browser_timeout = 950
|
156
|
+
end
|
157
|
+
|
158
|
+
# Save the configuration in a known location
|
159
|
+
PortalModule.save_configuration actual
|
160
|
+
|
161
|
+
# Reset the config (clean the slate)
|
162
|
+
PortalModule.configuration.reset
|
163
|
+
|
164
|
+
with_target_dir(actual_location + 'some/nested/path') do |start_dir|
|
165
|
+
PortalModule.load_configuration
|
166
|
+
end
|
167
|
+
|
168
|
+
expect( PortalModule.configuration.browser_timeout ).to eq 950
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end # describe PortalModule
|
175
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
if ENV['coverage']
|
6
|
+
raise 'simplecov only works on Ruby 1.9' unless RUBY_VERSION =~ /^1\.9/
|
7
|
+
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.start { add_filter "spec/" }
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'bundler/setup'
|
13
|
+
require 'rspec'
|
14
|
+
|
15
|
+
require 'pry-byebug'
|
16
|
+
require 'pry-doc'
|
17
|
+
require 'pry-docmore'
|
18
|
+
require 'pry-rescue'
|
19
|
+
require 'pry-stack_explorer'
|
20
|
+
|
21
|
+
require 'portal_module'
|
22
|
+
|
23
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
24
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
25
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
26
|
+
# loaded once.
|
27
|
+
#
|
28
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
29
|
+
RSpec.configure do |config|
|
30
|
+
config.run_all_when_everything_filtered = true
|
31
|
+
config.filter_run :focus
|
32
|
+
|
33
|
+
# Run specs in random order to surface order dependencies. If you find an
|
34
|
+
# order dependency and want to debug it, you can fix the order by providing
|
35
|
+
# the seed, which is printed after each run.
|
36
|
+
# --seed 1234
|
37
|
+
config.order = 'random'
|
38
|
+
|
39
|
+
config.mock_with :rspec do |mocks|
|
40
|
+
# This option should be set when all dependencies are being loaded
|
41
|
+
# before a spec run, as is the case in a typical spec helper. It will
|
42
|
+
# cause any verifying double instantiation for a class that does not
|
43
|
+
# exist to raise, protecting against incorrectly spelt names.
|
44
|
+
mocks.verify_doubled_constant_names = true
|
45
|
+
mocks.verify_partial_doubles = true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Dir["#{File.expand_path('./support', __dir__)}/*.rb"].each do |file|
|
50
|
+
require file #unless file =~/fakeweb\/.*\.rb/
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: asserts.rb
|
3
|
+
# Purpose:: spec assertion helper methods
|
4
|
+
#
|
5
|
+
##############################################################################
|
6
|
+
|
7
|
+
def assert_file_contains filename, str
|
8
|
+
result = `grep "#{str}" #{filename}`
|
9
|
+
fail "'#{str}' not found in #{filename}" if result.empty?
|
10
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: dirs.rb
|
3
|
+
# Purpose:: Spec directory helper methods
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 2015-03-29
|
6
|
+
#
|
7
|
+
##############################################################################
|
8
|
+
|
9
|
+
def spec_tmp_dir(relative_path = '')
|
10
|
+
here = Pathname.new(__dir__)
|
11
|
+
tmp = here + '../../tmp/spec'
|
12
|
+
tmp = tmp + relative_path unless relative_path.empty?
|
13
|
+
tmp.mkpath
|
14
|
+
tmp.realdirpath
|
15
|
+
end
|
16
|
+
|
17
|
+
def spec_data_dir
|
18
|
+
here = Pathname.new(__dir__)
|
19
|
+
tmp = here + '../data'
|
20
|
+
tmp.mkpath
|
21
|
+
tmp.realdirpath
|
22
|
+
end
|
23
|
+
|
24
|
+
def clean_target_dir dir
|
25
|
+
target_dir = spec_tmp_dir + Pathname(dir)
|
26
|
+
target_dir.rmtree if target_dir.exist?
|
27
|
+
target_dir.mkpath
|
28
|
+
target_dir
|
29
|
+
end
|
30
|
+
|
31
|
+
def with_target_dir dir
|
32
|
+
working_dir = clean_target_dir dir
|
33
|
+
FileUtils.cd working_dir do
|
34
|
+
yield(working_dir)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def copy_from_spec_data src_file, dest_file
|
39
|
+
src_path = spec_data_dir + src_file
|
40
|
+
dest_path = spec_tmp_dir + dest_file
|
41
|
+
dest_path.dirname.mkpath
|
42
|
+
FileUtils.cp src_path, dest_path
|
43
|
+
dest_path
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# DEPRECATED
|
48
|
+
#
|
49
|
+
def data_dir path = nil
|
50
|
+
return 'spec/data' unless path
|
51
|
+
return File.join('spec/data', path)
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: helpers.rb
|
3
|
+
# Purpose:: Spec helper methods
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 2015-03-29
|
6
|
+
##############################################################################
|
7
|
+
|
8
|
+
def run_with_args(args, client = nil, exitcode = false)
|
9
|
+
PortalModule::Runner.new(args, client, exitcode).execute!
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# Write a data structure to a yml file
|
14
|
+
#
|
15
|
+
def write_yaml_data_file filename, data
|
16
|
+
File.open(filename, 'w') { |f| f << YAML.dump(data) }
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Read a data from a yml file
|
21
|
+
#
|
22
|
+
def read_yaml_data_file filename
|
23
|
+
data = {}
|
24
|
+
File.open(filename, 'r') do |f|
|
25
|
+
data = YAML.load(f)
|
26
|
+
end
|
27
|
+
data
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_yml filename
|
31
|
+
YAML::load_file(filename)
|
32
|
+
end
|
33
|
+
|
34
|
+
def capture_output
|
35
|
+
fake_stdout = StringIO.new
|
36
|
+
actual_stdout = $stdout
|
37
|
+
$stdout = fake_stdout
|
38
|
+
yield
|
39
|
+
fake_stdout.rewind
|
40
|
+
fake_stdout.read
|
41
|
+
ensure
|
42
|
+
$stdout = actual_stdout
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,106 @@
|
|
1
|
+
include RSpec::Mocks::ExampleMethods
|
2
|
+
|
3
|
+
def mock_watir_browser
|
4
|
+
watir_browser = instance_double('Watir::Browser')
|
5
|
+
allow(watir_browser).to receive(:is_a?).with(anything()).and_return(false)
|
6
|
+
allow(watir_browser).to receive(:is_a?).with(Watir::Browser).and_return(true)
|
7
|
+
allow(watir_browser).to receive(:goto).with(anything()).and_return(true)
|
8
|
+
allow(watir_browser).to receive(:text_field).with(anything()).and_return(nil)
|
9
|
+
watir_browser
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Page Object Mocks
|
14
|
+
#
|
15
|
+
|
16
|
+
def mock_login_page(nav_to_page = true)
|
17
|
+
login_page = object_double(PortalModule::Pages::LoginPage.new(mock_watir_browser, nav_to_page))
|
18
|
+
allow(login_page).to receive(:login_as)#.with(anything()).and_return(nil)
|
19
|
+
allow(login_page).to receive(:logout)#.with(anything()).and_return(nil)
|
20
|
+
login_page
|
21
|
+
end
|
22
|
+
|
23
|
+
def mock_prequal_setup_page(nav_to_page = true)
|
24
|
+
prequal_setup_page = object_double(PortalModule::Pages::PrequalSetupPage.new(mock_watir_browser, nav_to_page))
|
25
|
+
end
|
26
|
+
|
27
|
+
def mock_data_transformation_page(nav_to_page = true)
|
28
|
+
obj = object_double(PortalModule::Pages::DataTransformationPage.new(mock_watir_browser, nav_to_page))
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Page Factory Mocks
|
33
|
+
#
|
34
|
+
|
35
|
+
def mock_page_factory_with_method(meth, obj)
|
36
|
+
page_factory = instance_double('PortalModule::PageFactory')
|
37
|
+
allow(page_factory).to receive(meth).and_return(obj)
|
38
|
+
page_factory
|
39
|
+
end
|
40
|
+
|
41
|
+
def mock_page_factory
|
42
|
+
obj = MockPageFactory.new
|
43
|
+
obj.login_page = mock_login_page
|
44
|
+
obj.loan_entry_page = mock_prequal_setup_page
|
45
|
+
obj.dts_page = mock_data_transformation_page
|
46
|
+
obj
|
47
|
+
end
|
48
|
+
|
49
|
+
class MockPageFactory
|
50
|
+
|
51
|
+
attr_writer :login_page
|
52
|
+
attr_writer :loan_entry_page
|
53
|
+
attr_writer :dts_page
|
54
|
+
|
55
|
+
def login_page(nav_to_page = true)
|
56
|
+
@login_page ||= mock_login_page(nav_to_page)
|
57
|
+
end
|
58
|
+
|
59
|
+
def loan_entry_page(nav_to_page = true)
|
60
|
+
@loan_entry_page ||= mock_prequal_setup_page(nav_to_page)
|
61
|
+
end
|
62
|
+
|
63
|
+
def dts_page(nav_to_page = true)
|
64
|
+
@dts_page ||= mock_data_transformation_page(nav_to_page)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Mock Client Objects
|
70
|
+
#
|
71
|
+
|
72
|
+
def mock_client(pg_factory = MockPageFactory.new)
|
73
|
+
mock_client = object_double(PortalModule::Client.new)
|
74
|
+
|
75
|
+
allow(mock_client).to receive(:login).with(anything, anything).and_return(nil)
|
76
|
+
allow(mock_client).to receive(:logout).and_return(nil)
|
77
|
+
allow(mock_client).to receive(:quit).and_return(nil)
|
78
|
+
allow(mock_client).to receive(:loan_entry).and_return(mock_loan_entry(pg_factory))
|
79
|
+
allow(mock_client).to receive(:dts).and_return(mock_dts(pg_factory))
|
80
|
+
|
81
|
+
mock_client
|
82
|
+
end
|
83
|
+
|
84
|
+
def mock_dts(pg_factory)
|
85
|
+
mock_dts = object_double(PortalModule::Dts.new(pg_factory))
|
86
|
+
|
87
|
+
allow(mock_dts).to receive(:activate).and_return(nil)
|
88
|
+
allow(mock_dts).to receive(:save).and_return(nil)
|
89
|
+
allow(mock_dts).to receive(:upload).and_return(nil)
|
90
|
+
allow(mock_dts).to receive(:download).and_return(nil)
|
91
|
+
allow(mock_dts).to receive(:set_org).and_return(nil)
|
92
|
+
|
93
|
+
mock_dts
|
94
|
+
end
|
95
|
+
|
96
|
+
def mock_loan_entry(pg_factory)
|
97
|
+
mock_obj = object_double(PortalModule::LoanEntry.new(pg_factory))
|
98
|
+
|
99
|
+
allow(mock_obj).to receive(:activate).and_return(nil)
|
100
|
+
allow(mock_obj).to receive(:upload).and_return(nil)
|
101
|
+
allow(mock_obj).to receive(:download).and_return(nil)
|
102
|
+
allow(mock_obj).to receive(:set_org).and_return(nil)
|
103
|
+
|
104
|
+
mock_obj
|
105
|
+
end
|
106
|
+
|