proxy_tester 0.0.1
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.
- data/.gitignore +22 -0
- data/.rdebugrc +7 -0
- data/.rspec +3 -0
- data/.simplecov +8 -0
- data/Gemfile +37 -0
- data/Gemfile.lock +199 -0
- data/LICENSE.txt +22 -0
- data/Procfile +1 -0
- data/README.md +582 -0
- data/Rakefile +64 -0
- data/bin/proxy_tester +11 -0
- data/db/migrate/20140314_create_environment.rb +8 -0
- data/files/config.yaml +1 -0
- data/files/example-config.erb +12 -0
- data/files/example-spec_helper.rb.erb +23 -0
- data/files/example-test_case.rb.erb +27 -0
- data/files/example-test_cases-gemfile.rb.erb +9 -0
- data/files/example-user_file.erb +4 -0
- data/lib/proxy_tester/actions/add_examples_to_test_cases_directory.rb +125 -0
- data/lib/proxy_tester/actions/clone_repository.rb +39 -0
- data/lib/proxy_tester/actions/create_directory.rb +33 -0
- data/lib/proxy_tester/actions/create_file.rb +55 -0
- data/lib/proxy_tester/actions/create_output.rb +36 -0
- data/lib/proxy_tester/actions/handle_error.rb +37 -0
- data/lib/proxy_tester/actions/initialize_application.rb +70 -0
- data/lib/proxy_tester/actions/show_config.rb +10 -0
- data/lib/proxy_tester/capybara_proxy.rb +54 -0
- data/lib/proxy_tester/capybara_proxy_pac.rb +62 -0
- data/lib/proxy_tester/cli/main.rb +59 -0
- data/lib/proxy_tester/config.rb +100 -0
- data/lib/proxy_tester/data.rb +23 -0
- data/lib/proxy_tester/database_session.rb +15 -0
- data/lib/proxy_tester/environment.rb +21 -0
- data/lib/proxy_tester/erb_generator.rb +34 -0
- data/lib/proxy_tester/error_handler.rb +107 -0
- data/lib/proxy_tester/error_messages.rb +82 -0
- data/lib/proxy_tester/exceptions.rb +53 -0
- data/lib/proxy_tester/git_file.rb +31 -0
- data/lib/proxy_tester/git_null_file.rb +32 -0
- data/lib/proxy_tester/git_repository.rb +120 -0
- data/lib/proxy_tester/handle_error.rb +37 -0
- data/lib/proxy_tester/locales/en-rails.yml +205 -0
- data/lib/proxy_tester/locales/en.yml +42 -0
- data/lib/proxy_tester/main.rb +46 -0
- data/lib/proxy_tester/models/user.rb +17 -0
- data/lib/proxy_tester/pac_result.rb +50 -0
- data/lib/proxy_tester/rspec/helper.rb +211 -0
- data/lib/proxy_tester/rspec_runner.rb +43 -0
- data/lib/proxy_tester/template_file.rb +19 -0
- data/lib/proxy_tester/template_repository.rb +22 -0
- data/lib/proxy_tester/ui_logger.rb +30 -0
- data/lib/proxy_tester/user_database.rb +24 -0
- data/lib/proxy_tester/version.rb +3 -0
- data/lib/proxy_tester.rb +54 -0
- data/proxy_tester.gemspec +34 -0
- data/script/acceptance_test +4 -0
- data/script/bootstrap +56 -0
- data/script/ci +3 -0
- data/script/console +14 -0
- data/script/release +3 -0
- data/script/test_web +22 -0
- data/script/unit_test +3 -0
- data/spec/actions/add_examples_to_test_cases_directory_spec.rb +52 -0
- data/spec/actions/clone_repository_spec.rb +83 -0
- data/spec/actions/create_directory_spec.rb +59 -0
- data/spec/actions/create_file_spec.rb +139 -0
- data/spec/actions/create_output_spec.rb +46 -0
- data/spec/actions/handle_error_spec.rb +74 -0
- data/spec/actions/initialize_application_spec.rb +40 -0
- data/spec/actions/show_config_spec.rb +22 -0
- data/spec/capybara_proxy_pac_spec.rb +42 -0
- data/spec/capybara_proxy_spec.rb +76 -0
- data/spec/config_spec.rb +86 -0
- data/spec/data_spec.rb +34 -0
- data/spec/environment_spec.rb +25 -0
- data/spec/erb_generator_spec.rb +31 -0
- data/spec/examples/proxy.pac +7 -0
- data/spec/factories.rb +8 -0
- data/spec/features/check_ssl_sites_spec.rb +8 -0
- data/spec/git_file_spec.rb +46 -0
- data/spec/git_repository_spec.rb +111 -0
- data/spec/main_spec.rb +25 -0
- data/spec/pac_result_spec.rb +20 -0
- data/spec/proxy_tester_spec_helper_spec.rb +137 -0
- data/spec/rspec_runner_spec.rb +29 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/capybara.rb +11 -0
- data/spec/support/database_cleaner.rb +14 -0
- data/spec/support/debugging.rb +3 -0
- data/spec/support/environment.rb +33 -0
- data/spec/support/example.rb +16 -0
- data/spec/support/factory_girl.rb +15 -0
- data/spec/support/filesystem.rb +19 -0
- data/spec/support/helper_features.rb +31 -0
- data/spec/support/matcher.rb +17 -0
- data/spec/support/reporting.rb +1 -0
- data/spec/support/rspec.rb +5 -0
- data/spec/support/string.rb +2 -0
- data/spec/template_file_spec.rb +25 -0
- data/spec/template_repository_spec.rb +44 -0
- data/spec/user_database_spec.rb +63 -0
- data/spec/user_spec.rb +62 -0
- metadata +398 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Spec helper' do
|
5
|
+
let(:valid_pac_file_url) do <<-EOS.strip_heredoc.chomp
|
6
|
+
function FindProxyForURL(url, host) {
|
7
|
+
if (url == 'www.heise.de') {
|
8
|
+
return "DIRECT";
|
9
|
+
} else {
|
10
|
+
return "PROXY localhost2:3128";
|
11
|
+
}
|
12
|
+
}
|
13
|
+
EOS
|
14
|
+
end
|
15
|
+
|
16
|
+
before :each do
|
17
|
+
@__proxy = CapybaraProxy.new
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#use_proxy' do
|
21
|
+
it 'defaults to host' do
|
22
|
+
@__proxy = double('proxy')
|
23
|
+
expect(proxy).to receive(:host=).with('localhost1')
|
24
|
+
expect(proxy).to receive(:port=).with('3128')
|
25
|
+
|
26
|
+
use_proxy 'localhost1:3128'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'fails on invalid symbol' do
|
30
|
+
expect {
|
31
|
+
use_proxy :asdf, 'localhost1:3128'
|
32
|
+
}.to raise_error Exceptions::SyntaxInvalid
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'works with :host and connection string' do
|
36
|
+
@__proxy = double('proxy')
|
37
|
+
expect(proxy).to receive(:host=).with('localhost1')
|
38
|
+
expect(proxy).to receive(:port=).with('3128')
|
39
|
+
|
40
|
+
use_proxy :host, 'localhost1:3128'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'works with :pac and proxy pac' do
|
44
|
+
@__proxy_pac = double('proxy_pac')
|
45
|
+
expect(proxy_pac).to receive(:pac_file=).with('http://localhost1:4567')
|
46
|
+
|
47
|
+
use_proxy :pac, 'http://localhost1:4567'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'finds proxy for proxy pac' do
|
51
|
+
@__proxy = double('proxy')
|
52
|
+
expect(proxy).to receive(:host=).with('localhost2')
|
53
|
+
expect(proxy).to receive(:port=).with('3128')
|
54
|
+
allow(proxy).to receive(:as_phantomjs_arguments).and_return(%w{--proxy localhost2:3128})
|
55
|
+
allow(proxy).to receive(:to_sym).and_return(:localhost2_3128)
|
56
|
+
|
57
|
+
file = create_file 'proxy.pac', valid_pac_file_url
|
58
|
+
use_proxy :pac, file
|
59
|
+
|
60
|
+
begin
|
61
|
+
use_timeout(0) do
|
62
|
+
visit 'http://www.example.com'
|
63
|
+
end
|
64
|
+
rescue Exceptions::FetchUrlTimeout
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'accepts an type as well (long form)' do
|
69
|
+
@__proxy = double('proxy')
|
70
|
+
expect(proxy).to receive(:host=).with('localhost1')
|
71
|
+
expect(proxy).to receive(:port=).with('3128')
|
72
|
+
expect(proxy).to receive(:type=).with(:none)
|
73
|
+
|
74
|
+
use_proxy :host, 'localhost1:3128', type: :none
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'accepts an type as well (short form)' do
|
78
|
+
@__proxy = double('proxy')
|
79
|
+
expect(proxy).to receive(:host=).with('localhost1')
|
80
|
+
expect(proxy).to receive(:port=).with('3128')
|
81
|
+
expect(proxy).to receive(:type=).with(:none)
|
82
|
+
|
83
|
+
use_proxy 'localhost1:3128', type: :none
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context '#use_time' do
|
88
|
+
it 'sets time for use in proxy pac' do
|
89
|
+
time = Time.now
|
90
|
+
|
91
|
+
@__proxy_pac = double('proxy_pac')
|
92
|
+
expect(proxy_pac).to receive(:time=).with(time)
|
93
|
+
|
94
|
+
use_time time
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context '#use_client_ip' do
|
99
|
+
it 'sets client ip for use in proxy pac' do
|
100
|
+
client_ip = IPAddr.new('127.0.0.1').to_s
|
101
|
+
|
102
|
+
@__proxy_pac = double('proxy_pac')
|
103
|
+
expect(proxy_pac).to receive(:client_ip=).with(client_ip)
|
104
|
+
|
105
|
+
use_client_ip client_ip
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context '#use_user' do
|
110
|
+
it 'works with a valid user' do
|
111
|
+
user = create :user
|
112
|
+
|
113
|
+
@__proxy = double('proxy')
|
114
|
+
expect(proxy).to receive(:user=).with(user)
|
115
|
+
allow(proxy).to receive(:as_phantomjs_arguments).and_return([])
|
116
|
+
|
117
|
+
use_user 'user'
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'works with a valid user via proxy' do
|
121
|
+
create :user
|
122
|
+
|
123
|
+
use_proxy 'localhost:3128'
|
124
|
+
use_user 'user'
|
125
|
+
|
126
|
+
visit('http://www.example.org')
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'fails with an invalid user' do
|
130
|
+
expect {
|
131
|
+
silence :stderr do
|
132
|
+
use_user 'user'
|
133
|
+
end
|
134
|
+
}.to raise_error Exceptions::ProxyUserInvalid
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe RspecRunner do
|
5
|
+
context '#initialize' do
|
6
|
+
#it 'accepts a config' do
|
7
|
+
# config = double('config')
|
8
|
+
# expect {
|
9
|
+
# RspecRunner.new(config)
|
10
|
+
# }.not_to raise_error
|
11
|
+
#end
|
12
|
+
end
|
13
|
+
|
14
|
+
#context '#run' do
|
15
|
+
# it 'runs test' do
|
16
|
+
# create_file 'test_rspec_runner_spec.rb', <<-EOS.strip_heredoc
|
17
|
+
# describe 'Test' do
|
18
|
+
# it 'is true' do
|
19
|
+
# expect(true).to be true
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
# EOS
|
23
|
+
|
24
|
+
# runner = RspecRunner.new(test_cases_directory: working_directory)
|
25
|
+
# runner.run
|
26
|
+
# end
|
27
|
+
#end
|
28
|
+
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH << ::File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.command_name 'rspec'
|
6
|
+
SimpleCov.start
|
7
|
+
|
8
|
+
# Pull in all of the gems including those in the `test` group
|
9
|
+
require 'bundler'
|
10
|
+
Bundler.require :default, :test, :development
|
11
|
+
|
12
|
+
# Loading support files
|
13
|
+
Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
|
14
|
+
|
15
|
+
include ProxyTester
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
RSpec.configure do |config|
|
3
|
+
|
4
|
+
config.before(:suite) do
|
5
|
+
DatabaseCleaner.strategy = :transaction
|
6
|
+
# DatabaseCleaner.clean_with :truncation
|
7
|
+
end
|
8
|
+
|
9
|
+
config.around(:each) do |example|
|
10
|
+
DatabaseCleaner.start
|
11
|
+
example.run
|
12
|
+
DatabaseCleaner.clean
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'fedux_org/stdlib/environment'
|
3
|
+
|
4
|
+
module ProxyTester
|
5
|
+
module SpecHelper
|
6
|
+
module Environment
|
7
|
+
include FeduxOrg::Stdlib::Environment
|
8
|
+
alias_method :with_environment, :isolated_environment
|
9
|
+
|
10
|
+
def mock_stdin(&block)
|
11
|
+
old_stdin = $stdin
|
12
|
+
$stdin = double('stdin')
|
13
|
+
|
14
|
+
block.call
|
15
|
+
ensure
|
16
|
+
$stdin = old_stdin
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
RSpec.configure do |c|
|
23
|
+
c.include ProxyTester::SpecHelper::Environment
|
24
|
+
c.before(:suite) do
|
25
|
+
%w{
|
26
|
+
http_proxy
|
27
|
+
https_proxy
|
28
|
+
HTTP_PROXY
|
29
|
+
HTTPS_PROXY
|
30
|
+
}.each { |var| ENV.delete(var) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ProxyTester
|
4
|
+
module SpecHelper
|
5
|
+
module Example
|
6
|
+
def example_file(path)
|
7
|
+
File.expand_path("../../examples/#{path}", __FILE__)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |c|
|
14
|
+
c.include ProxyTester::SpecHelper::Example
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'fedux_org/stdlib/filesystem'
|
2
|
+
|
3
|
+
module ProxyTester
|
4
|
+
module SpecHelper
|
5
|
+
module Filesystem
|
6
|
+
include FeduxOrg::Stdlib::Filesystem
|
7
|
+
|
8
|
+
def root_directory
|
9
|
+
::File.expand_path('../../../', __FILE__)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# encoding: utf-8
|
16
|
+
RSpec.configure do |c|
|
17
|
+
c.include ProxyTester::SpecHelper::Filesystem
|
18
|
+
c.before(:each) { cleanup_working_directory }
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative 'capybara'
|
3
|
+
|
4
|
+
module InternetBrowsingBnk
|
5
|
+
module SpecHelper
|
6
|
+
module Features
|
7
|
+
def search_for(options = {})
|
8
|
+
url = options.fetch(:url)
|
9
|
+
content = options.fetch(:content)
|
10
|
+
client_ip = options.fetch(:client_ip, nil)
|
11
|
+
time = options.fetch(:time, nil)
|
12
|
+
pac_file = options.fetch(:pac_file, '/file.pac')
|
13
|
+
|
14
|
+
visit(pac_file)
|
15
|
+
within('#search') do
|
16
|
+
fill_in 'url', :with => url
|
17
|
+
fill_in('client_ip', :with => client_ip) if client_ip
|
18
|
+
fill_in('time', :with => time) if time
|
19
|
+
end
|
20
|
+
click_on('Search')
|
21
|
+
expect(page).to have_content(content)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# encoding: utf-8
|
28
|
+
RSpec.configure do |c|
|
29
|
+
c.include InternetBrowsingBnk::SpecHelper::Features
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
RSpec::Matchers.define :be_a_multiple_of do |expected|
|
2
|
+
match do |actual|
|
3
|
+
actual % expected == 0
|
4
|
+
end
|
5
|
+
|
6
|
+
failure_message_for_should do |actual|
|
7
|
+
"expected that #{actual} would be a precise multiple of #{expected}"
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_for_should_not do |actual|
|
11
|
+
"expected that #{actual} would not be a precise multiple of #{expected}"
|
12
|
+
end
|
13
|
+
|
14
|
+
description do
|
15
|
+
"be a precise multiple of #{expected}"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_support/core_ext/kernel/reporting'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe TemplateFile do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'requires a path' do
|
7
|
+
TemplateFile.new('/path/asfd')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context '#name' do
|
12
|
+
it 'has a name based on path' do
|
13
|
+
file = TemplateFile.new('/path/asdf')
|
14
|
+
expect(file.name).to eq(:asdf)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context '#read' do
|
19
|
+
it 'reads content' do
|
20
|
+
file = create_file('asdf', 'content')
|
21
|
+
file = TemplateFile.new(file)
|
22
|
+
expect(file.read).to eq('content')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe TemplateRepository do
|
5
|
+
let(:creator_klass) do
|
6
|
+
Class.new do
|
7
|
+
def initialize(path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
:template
|
12
|
+
end
|
13
|
+
|
14
|
+
def content
|
15
|
+
'content'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#initialize' do
|
21
|
+
it 'accepts a path' do
|
22
|
+
TemplateRepository.new('path', creator_klass)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#find' do
|
27
|
+
|
28
|
+
it 'finds a template by name' do
|
29
|
+
dir = create_directory('repo')
|
30
|
+
file = create_file('repo/template.erb')
|
31
|
+
repo = TemplateRepository.new(dir, creator_klass)
|
32
|
+
template_file = repo.find(::File.basename(file, '.*'))
|
33
|
+
expect(template_file.name).to eq(:template)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'finds a template by name' do
|
37
|
+
dir = create_directory('repo')
|
38
|
+
file = create_file('repo/template.erb')
|
39
|
+
repo = TemplateRepository.new(dir, creator_klass)
|
40
|
+
template_file = repo.find(::File.basename(file, '.*').to_sym)
|
41
|
+
expect(template_file.name).to eq(:template)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe UserDatabase do
|
5
|
+
let(:valid_user_file) {
|
6
|
+
create_file 'user.csv', <<-EOS.strip_heredoc
|
7
|
+
"user","password"
|
8
|
+
"user1","password1"
|
9
|
+
EOS
|
10
|
+
}
|
11
|
+
|
12
|
+
context '#initialize' do
|
13
|
+
it 'accepts a file for user database' do
|
14
|
+
expect {
|
15
|
+
UserDatabase.new(valid_user_file)
|
16
|
+
}.not_to raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#create_users' do
|
21
|
+
it 'creates instances' do
|
22
|
+
creator = double('creator')
|
23
|
+
allow(creator).to receive(:create!)
|
24
|
+
|
25
|
+
db = UserDatabase.new(valid_user_file)
|
26
|
+
db.create_users(creator)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'raises an exception on invalid user record' do
|
30
|
+
message = Class.new do
|
31
|
+
class << self
|
32
|
+
attr_reader :i18n_scope
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_reader :errors
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
@errors = ActiveModel::Errors.new(self)
|
39
|
+
end
|
40
|
+
end.new
|
41
|
+
|
42
|
+
creator = double('creator')
|
43
|
+
allow(creator).to receive(:create!) { raise ActiveRecord::RecordInvalid, message }
|
44
|
+
|
45
|
+
db = UserDatabase.new(valid_user_file)
|
46
|
+
|
47
|
+
expect {
|
48
|
+
db.create_users(creator)
|
49
|
+
}.to raise_error Exceptions::UserRecordInvalid
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'raises an exception if csv file does not exist' do
|
54
|
+
creator = double('creator')
|
55
|
+
allow(creator).to receive(:create!)
|
56
|
+
|
57
|
+
db = UserDatabase.new('asdf')
|
58
|
+
expect {
|
59
|
+
db.create_users(creator)
|
60
|
+
}.to raise_error Exceptions::UserFileNotFound
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe User do
|
5
|
+
context '.create' do
|
6
|
+
it 'requires a name and a password' do
|
7
|
+
expect {
|
8
|
+
create(:user,
|
9
|
+
name: 'name',
|
10
|
+
password: 'password',
|
11
|
+
)
|
12
|
+
}.not_to raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'fails on missing name' do
|
16
|
+
expect {
|
17
|
+
create(:user,
|
18
|
+
name: nil,
|
19
|
+
password: 'password',
|
20
|
+
)
|
21
|
+
}.to raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'fails on missing password' do
|
25
|
+
expect {
|
26
|
+
create(:user,
|
27
|
+
name: 'user1',
|
28
|
+
password: nil,
|
29
|
+
)
|
30
|
+
}.to raise_error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context '.find_by!' do
|
35
|
+
it 'finds a user' do
|
36
|
+
create :user
|
37
|
+
|
38
|
+
expect {
|
39
|
+
User.find_by!(name: 'user')
|
40
|
+
}.not_to raise_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context '.load_from' do
|
45
|
+
it 'creates users from source' do
|
46
|
+
source = double('source')
|
47
|
+
expect(source).to receive(:create_users).with(User)
|
48
|
+
|
49
|
+
User.load_from source
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context '#to_s' do
|
54
|
+
it 'returns the user as textual representation' do
|
55
|
+
user = create(:user,
|
56
|
+
name: 'name',
|
57
|
+
password: 'password',
|
58
|
+
)
|
59
|
+
expect(user.to_string).to eq('name:password')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|