learn-test 3.2.3 → 3.3.0.pre.4

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.
@@ -0,0 +1 @@
1
+ {"version":"3.9.2","examples":[{"id":"./spec/dog_spec.rb[1:1]","description":"runs the spec spec correctly","full_description":"Dog runs the spec spec correctly","status":"passed","file_path":"./spec/dog_spec.rb","line_number":6,"run_time":0.000423,"pending_message":null},{"id":"./spec/dog_spec.rb[1:2]","description":"has multiple specs","full_description":"Dog has multiple specs","status":"passed","file_path":"./spec/dog_spec.rb","line_number":10,"run_time":4.8e-05,"pending_message":null},{"id":"./spec/dog_spec.rb[1:3]","description":"accepts more than one example","full_description":"Dog accepts more than one example","status":"passed","file_path":"./spec/dog_spec.rb","line_number":14,"run_time":3.6e-05,"pending_message":null}],"summary":{"duration":0.001252,"example_count":3,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":0},"summary_line":"3 examples, 0 failures"}
@@ -1,95 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # This file was generated by the `rspec --init` command. Conventionally, all
4
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
- # The generated `.rspec` file contains `--require spec_helper` which will cause
6
- # this file to always be loaded, without a need to explicitly require it in any
7
- # files.
8
- #
9
- # Given that it is always loaded, you are encouraged to keep this file as
10
- # light-weight as possible. Requiring heavyweight dependencies from this file
11
- # will add to the boot time of your test suite on EVERY test run, even for an
12
- # individual file that may not need all of that loaded. Instead, consider making
13
- # a separate helper file that requires the additional dependencies and performs
14
- # the additional setup, and require it from the spec files that actually need
15
- # it.
16
- #
17
- # The `.rspec` file also contains a few flags that are not defaults but that
18
- # users commonly want.
19
- #
20
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
3
  require_relative '../lib/dog'
22
4
 
23
5
  RSpec.configure do |config|
24
- # rspec-expectations config goes here. You can use an alternate
25
- # assertion/expectation library such as wrong or the stdlib/minitest
26
- # assertions if you prefer.
27
6
  config.expect_with :rspec do |expectations|
28
- # This option will default to `true` in RSpec 4. It makes the `description`
29
- # and `failure_message` of custom matchers include text for helper methods
30
- # defined using `chain`, e.g.:
31
- # be_bigger_than(2).and_smaller_than(4).description
32
- # # => "be bigger than 2 and smaller than 4"
33
- # ...rather than:
34
- # # => "be bigger than 2"
35
7
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
36
8
  end
37
9
 
38
- # rspec-mocks config goes here. You can use an alternate test double
39
- # library (such as bogus or mocha) by changing the `mock_with` option here.
40
10
  config.mock_with :rspec do |mocks|
41
- # Prevents you from mocking or stubbing a method that does not exist on
42
- # a real object. This is generally recommended, and will default to
43
- # `true` in RSpec 4.
44
11
  mocks.verify_partial_doubles = true
45
12
  end
46
-
47
- # The settings below are suggested to provide a good initial experience
48
- # with RSpec, but feel free to customize to your heart's content.
49
- =begin
50
- # These two settings work together to allow you to limit a spec run
51
- # to individual examples or groups you care about by tagging them with
52
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
53
- # get run.
54
- config.filter_run :focus
55
- config.run_all_when_everything_filtered = true
56
-
57
- # Limits the available syntax to the non-monkey patched syntax that is
58
- # recommended. For more details, see:
59
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
60
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
61
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
62
- config.disable_monkey_patching!
63
-
64
- # This setting enables warnings. It's recommended, but in some cases may
65
- # be too noisy due to issues in dependencies.
66
- config.warnings = true
67
-
68
- # Many RSpec users commonly either run the entire suite or an individual
69
- # file, and it's useful to allow more verbose output when running an
70
- # individual spec file.
71
- if config.files_to_run.one?
72
- # Use the documentation formatter for detailed output,
73
- # unless a formatter has already been configured
74
- # (e.g. via a command-line flag).
75
- config.default_formatter = 'doc'
76
- end
77
-
78
- # Print the 10 slowest examples and example groups at the
79
- # end of the spec run, to help surface which specs are running
80
- # particularly slow.
81
- config.profile_examples = 10
82
-
83
- # Run specs in random order to surface order dependencies. If you find an
84
- # order dependency and want to debug it, you can fix the order by providing
85
- # the seed, which is printed after each run.
86
- # --seed 1234
87
- config.order = :random
88
-
89
- # Seed global randomization in this process using the `--seed` CLI option.
90
- # Setting this allows you to use `--seed` to deterministically reproduce
91
- # test failures related to randomization by passing the same `--seed` value
92
- # as the one that triggered the failure.
93
- Kernel.srand config.seed
94
- =end
95
13
  end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe LearnTest::Git::Wip::Base do
4
+ describe 'attr_reader' do
5
+ let(:base) { LearnTest::Git::Base.open('./') }
6
+ let(:message) { 'foobar' }
7
+ let(:instance) do
8
+ described_class.new(
9
+ base: base,
10
+ message: message
11
+ )
12
+ end
13
+
14
+ it 'should have :working_branch, :wip_branch' do
15
+ expect(instance).to respond_to(:working_branch, :wip_branch)
16
+ end
17
+ end
18
+
19
+ describe '.process!', type: :aruba do
20
+ let!(:path) { File.join Aruba.config.home_directory, 'example' }
21
+ let(:base) { LearnTest::Git::Base.open(path) }
22
+ let(:message) { 'foobar' }
23
+ let(:instance) do
24
+ described_class.new(
25
+ base: base,
26
+ message: message
27
+ )
28
+ end
29
+
30
+ def initialize_repo(commit: true)
31
+ create_directory 'example'
32
+ cd 'example'
33
+ write_file 'README.md', 'Hello World'
34
+ git_init
35
+
36
+ if commit # rubocop:disable Style/GuardClause
37
+ git_add
38
+ git_commit 'Initial Commit'
39
+ end
40
+ end
41
+
42
+ context 'no commits' do
43
+ before(:each) { initialize_repo(commit: false) }
44
+
45
+ it 'should raise' do
46
+ expect { instance.process! }.to raise_error(LearnTest::Git::Wip::NoCommitsError)
47
+ end
48
+ end
49
+
50
+ xcontext 'no changes' do
51
+ before(:each) { initialize_repo }
52
+
53
+ it 'should raise' do
54
+ expect { instance.process! }.to raise_error(LearnTest::Git::Wip::NoChangesError)
55
+ end
56
+ end
57
+
58
+ context 'changes' do
59
+ context 'staged' do
60
+ before :each do
61
+ initialize_repo
62
+ write_file 'test.rb', ''
63
+ end
64
+
65
+ it 'should process successfully' do
66
+ instance.process!
67
+
68
+ expect(instance.success?).to eq(true)
69
+ end
70
+ end
71
+
72
+ context 'committed' do
73
+ before :each do
74
+ initialize_repo
75
+ write_file 'test.rb', ''
76
+
77
+ git_add
78
+ git_commit 'foo'
79
+ end
80
+
81
+ it 'should process successfully' do
82
+ instance.process!
83
+
84
+ expect(instance.success?).to eq(true)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe LearnTest::Git::Wip::Branch do
4
+ let(:base) { LearnTest::Git::Base.open('./') }
5
+ let(:name) { base.current_branch }
6
+ let(:branch) do
7
+ described_class.new(
8
+ base: base,
9
+ name: name
10
+ )
11
+ end
12
+
13
+ let(:sha1) { Digest::SHA1.new.hexdigest }
14
+ let(:nothing_to_commit_error_msg) { 'nothing to commit, working directory clean' }
15
+ let(:no_commits_error_msg) do
16
+ "fatal: ambiguous argument '#{name}': unknown revision or path not in the working tree."
17
+ end
18
+
19
+ describe 'accessors' do
20
+ it 'should have :parent, :parent=' do
21
+ expect(branch).to respond_to(:parent, :parent=)
22
+ end
23
+ end
24
+
25
+ describe '.new' do
26
+ it 'should require :base' do
27
+ expect { described_class.new(base: {}) }.to raise_error(ArgumentError, /name/)
28
+ end
29
+
30
+ it 'should require :name' do
31
+ expect { described_class.new(name: 'foo') }.to raise_error(ArgumentError, /base/)
32
+ end
33
+ end
34
+
35
+ describe '.to_s' do
36
+ it 'should return @name' do
37
+ expect(branch.to_s).to eq(name)
38
+ end
39
+ end
40
+
41
+ describe '.last_revision' do
42
+ context 'success' do
43
+ it 'should return a SHA' do
44
+ expect(base)
45
+ .to receive(:revparse)
46
+ .with(name)
47
+ .and_return(sha1)
48
+
49
+ expect(branch.last_revision).to eq(sha1)
50
+ end
51
+
52
+ it 'should only run revparse once' do
53
+ expect(base)
54
+ .to receive(:revparse)
55
+ .with(name)
56
+ .and_return(sha1)
57
+ .once
58
+
59
+ expect(branch.last_revision).to eq(sha1)
60
+ expect(branch.last_revision).to eq(sha1)
61
+ end
62
+ end
63
+
64
+ context 'hide expected Git errors' do
65
+ it 'should hide no commits error' do
66
+ expect(base)
67
+ .to receive(:revparse)
68
+ .with(name)
69
+ .and_raise(::Git::GitExecuteError, no_commits_error_msg)
70
+
71
+ expect { branch.last_revision }.to_not raise_error
72
+ end
73
+
74
+ it 'should return false' do
75
+ expect(base)
76
+ .to receive(:revparse)
77
+ .with(name)
78
+ .and_raise(::Git::GitExecuteError, no_commits_error_msg)
79
+
80
+ expect(branch.last_revision).to eq(false)
81
+ end
82
+ end
83
+
84
+ context 'raise expected Git errors' do
85
+ it 'should raise no commits error' do
86
+ expect(base)
87
+ .to receive(:revparse)
88
+ .with(name)
89
+ .and_raise(::Git::GitExecuteError, no_commits_error_msg)
90
+
91
+ expect do
92
+ branch.last_revision(raise_no_commits: true)
93
+ end.to raise_error(
94
+ LearnTest::Git::Wip::NoCommitsError, "Branch `#{name}` doesn't have any commits. Please commit and try again."
95
+ )
96
+ end
97
+ end
98
+
99
+ context 'raise unexpected Git errors' do
100
+ it 'should raise no commits error' do
101
+ expect(base)
102
+ .to receive(:revparse)
103
+ .with(name)
104
+ .and_raise(::Git::GitExecuteError, nothing_to_commit_error_msg)
105
+
106
+ expect { branch.last_revision }.to raise_error(::Git::GitExecuteError, nothing_to_commit_error_msg)
107
+ end
108
+ end
109
+
110
+ context 'raise unexpected errors' do
111
+ it 'should raise' do
112
+ expect(base)
113
+ .to receive(:revparse)
114
+ .with(name)
115
+ .and_raise(StandardError)
116
+
117
+ expect { branch.last_revision }.to raise_error(StandardError)
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe LearnTest::Git::Wip do
4
+ let(:branch) { rand(0..999_999).to_s }
5
+
6
+ describe LearnTest::Git::Wip::Error do
7
+ it 'should inherit from StandardError' do
8
+ expect(described_class).to be < StandardError
9
+ end
10
+ end
11
+
12
+ describe LearnTest::Git::Wip::NoChangesError do
13
+ it 'should inherit from Error' do
14
+ expect(described_class).to be < LearnTest::Git::Wip::Error
15
+ end
16
+
17
+ it 'should require a branch' do
18
+ expect { described_class.new }.to raise_error(ArgumentError)
19
+ end
20
+
21
+ it 'should have the correct messaging' do
22
+ error = described_class.new(branch)
23
+ expect(error.message).to eq "No changes found on `#{branch}`"
24
+ end
25
+ end
26
+
27
+ describe LearnTest::Git::Wip::NoCommitsError do
28
+ it 'should inherit from Error' do
29
+ expect(described_class).to be < LearnTest::Git::Wip::Error
30
+ end
31
+
32
+ it 'should require a branch' do
33
+ expect { described_class.new }.to raise_error(ArgumentError)
34
+ end
35
+
36
+ it 'should have the correct messaging' do
37
+ error = described_class.new(branch)
38
+ expect(error.message).to eq "Branch `#{branch}` doesn't have any commits. Please commit and try again."
39
+ end
40
+ end
41
+ end
@@ -1,47 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe LearnTest::GitWip do
4
- subject { described_class }
5
-
6
- let!(:working_branch) { 'develop' }
7
- let!(:git_url) { 'https://github.com/learn-co/learn-test' }
8
- let!(:git_base) { instance_double(Git::Base) }
9
-
10
- let(:wait_thr) { double }
11
- let(:wait_thr_value) { double }
12
- let(:stdout_and_stderr) { double }
13
-
14
- context 'success' do
15
- it 'should return the git url' do
16
- expect(Git::Base).to receive(:open).with('./', { log: false }).and_return(git_base)
17
- expect(git_base).to receive(:current_branch).and_return(working_branch)
3
+ describe LearnTest::Git do
4
+ describe '.open' do
5
+ context 'defaults' do
6
+ it 'should instantiate LearnTest::Git::Base' do
7
+ expect(LearnTest::Git::Base).to receive(:open).with('./', {})
8
+ LearnTest::Git.open
9
+ end
10
+ end
18
11
 
19
- expect(wait_thr).to receive(:value).and_return(wait_thr_value)
20
- expect(wait_thr_value).to receive(:exitstatus).and_return(0)
12
+ context 'with options' do
13
+ it 'should instantiate LearnTest::Git::Base' do
14
+ directory = './foo'
15
+ options = { logger: false }
21
16
 
22
- expect(Open3).to receive(:popen3).and_yield(nil, nil, nil, wait_thr)
17
+ expect(LearnTest::Git::Base).to receive(:open).with(directory, options)
23
18
 
24
- expect(git_base).to receive_message_chain(:config, :[]).with('remote.origin.url').and_return("#{git_url}.git")
25
- expect(subject.run!).to eq("#{git_url}/tree/wip")
19
+ LearnTest::Git.open(
20
+ directory: directory,
21
+ options: options
22
+ )
23
+ end
26
24
  end
27
25
  end
28
26
 
29
- context 'failure' do
30
- it 'should return false on process error' do
31
- expect(Git::Base).to receive(:open).with('./', { log: false }).and_return(git_base)
32
- expect(git_base).to receive(:current_branch).and_return(working_branch)
27
+ describe LearnTest::Git::Base do
28
+ it 'should inherit from ::Git::Base' do
29
+ expect(LearnTest::Git::Base).to be < ::Git::Base
30
+ end
33
31
 
34
- expect(wait_thr).to receive(:value).and_return(wait_thr_value)
35
- expect(wait_thr_value).to receive(:exitstatus).and_return(1)
32
+ describe '#wip' do
33
+ let!(:repo) { described_class.open('./') }
34
+ let!(:message) { 'FooBar' }
35
+ let!(:wip) { double(LearnTest::Git::Wip::Base) }
36
36
 
37
- expect(Open3).to receive(:popen3).and_yield(nil, nil, nil, wait_thr)
37
+ it 'should require a :message' do
38
+ expect { repo.wip }.to raise_error(ArgumentError)
39
+ end
38
40
 
39
- expect(subject.run!).to eq(false)
40
- end
41
+ it 'should instantiate and run .process!' do
42
+ expect(LearnTest::Git::Wip::Base)
43
+ .to receive(:new)
44
+ .with(base: repo, message: message)
45
+ .and_return(wip)
46
+
47
+ expect(wip).to receive(:process!)
41
48
 
42
- it 'should return false on StandardError' do
43
- expect(Git::Base).to receive(:open).and_raise(StandardError)
44
- expect(subject.run!).to eq(false)
49
+ expect(repo.wip(message: message)).to eq(wip)
50
+ end
45
51
  end
46
52
  end
47
53
  end
@@ -1,15 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
- require_relative '../../lib/learn_test/reporter'
6
-
7
3
  require 'tempfile'
8
4
  require 'json'
9
5
 
10
6
  describe LearnTest::Reporter do
11
7
  let!(:client) { instance_spy(LearnTest::Client) }
12
- let!(:git_tree) { 'https://github.com/learn-co/learn-test/tree/wip' }
8
+ let!(:git_base) { double(LearnTest::Git::Base) }
9
+ let!(:git_wip) { double(LearnTest::Git::Wip::Base) }
13
10
  let!(:strategy) do
14
11
  instance_spy(
15
12
  LearnTest::Strategy,
@@ -45,42 +42,75 @@ describe LearnTest::Reporter do
45
42
  end
46
43
 
47
44
  context 'sync with Github' do
48
- it 'should not run LearnTest::GitWip, if :post_results fails' do
45
+ it 'should not run LearnTest::Git::Wip, if :post_results fails' do
49
46
  expect(client).to receive(:post_results).and_return(false)
50
- expect(LearnTest::GitWip).to_not receive(:run!)
47
+ expect(LearnTest::Git).to_not receive(:open)
51
48
 
52
49
  reporter.report
53
50
  end
54
51
 
55
- it 'should run LearnTest::GitWip.run!' do
52
+ it 'should run LearnTest::Git::Wip' do
53
+ branch = double(LearnTest::Git::Wip::Branch)
54
+ branch_name = 'foo'
55
+
56
56
  expect(client).to receive(:post_results).and_return(true)
57
- expect(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
57
+ expect(LearnTest::Git).to receive(:open).and_return(git_base)
58
+ expect(git_base).to receive(:wip).and_return(git_wip)
59
+ expect(git_wip).to receive(:success?).and_return(true)
60
+
61
+ expect(branch).to receive(:to_s).and_return(branch_name)
62
+ expect(git_wip).to receive(:wip_branch).and_return(branch)
63
+
64
+ expect(git_base)
65
+ .to receive(:push)
66
+ .with('origin', "#{branch_name}:refs/heads/fis-wip", { force: true })
58
67
 
59
68
  reporter.report
60
69
  end
61
70
 
62
71
  it 'should not output an error message without debug' do
63
72
  expect(client).to receive(:post_results).and_return(true)
64
- expect(LearnTest::GitWip).to receive(:run!).and_return(false)
73
+ expect(LearnTest::Git).to receive(:open).and_return(git_base)
74
+ expect(git_base).to receive(:wip).and_return(git_wip)
75
+ expect(git_wip).to receive(:success?).and_return(false)
76
+
77
+ expect(git_base).to_not receive(:push)
65
78
 
66
79
  expect { reporter.report }.to_not output.to_stdout
67
80
  end
68
81
 
69
82
  it 'should output an error message with debug' do
70
83
  expect(client).to receive(:post_results).and_return(true)
71
- expect(LearnTest::GitWip).to receive(:run!).and_return(false)
84
+
85
+ expect(LearnTest::Git).to receive(:open).and_return(git_base)
86
+ expect(git_base).to receive(:wip).and_return(git_wip)
87
+ expect(git_wip).to receive(:success?).and_return(false)
88
+
89
+ expect(git_base).to_not receive(:push)
72
90
 
73
91
  expect do
74
92
  reporter.debug = true
75
93
  reporter.report
76
- end.to output(/Github/i).to_stdout
94
+ end.to output(/There was a problem creating your WIP branch/i).to_stdout
77
95
  end
78
96
  end
79
97
 
80
98
  it 'posts results to the service endpoint' do
81
- reporter.report
99
+ branch = double(LearnTest::Git::Wip::Branch)
100
+ branch_name = 'bar'
101
+
102
+ expect(LearnTest::Git).to receive(:open).and_return(git_base)
103
+ expect(git_base).to receive(:wip).and_return(git_wip)
104
+ expect(git_wip).to receive(:success?).and_return(true)
82
105
 
83
- allow(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
106
+ expect(branch).to receive(:to_s).and_return(branch_name)
107
+ expect(git_wip).to receive(:wip_branch).and_return(branch)
108
+
109
+ expect(git_base)
110
+ .to receive(:push)
111
+ .with('origin', "#{branch_name}:refs/heads/fis-wip", { force: true })
112
+
113
+ reporter.report
84
114
 
85
115
  expect(client).to have_received(:post_results)
86
116
  .with(strategy.service_endpoint, strategy.results)
@@ -131,7 +161,6 @@ describe LearnTest::Reporter do
131
161
 
132
162
  it 'deletes the output file when all reports are sent successfully' do
133
163
  allow(client).to receive(:post_results).and_return(true)
134
- allow(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
135
164
 
136
165
  reports = { hello: ['world'] }
137
166
 
@@ -145,7 +174,6 @@ describe LearnTest::Reporter do
145
174
 
146
175
  it 'writes the remaining reports from the output file' do
147
176
  allow(client).to receive(:post_results).and_return(true, false)
148
- allow(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
149
177
 
150
178
  reports = { success: ['world'], failure: ['hello'] }
151
179