Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit e9bfa73

Browse files
authored
Merge pull request #42 from BranchMetrics/unit-tests
Unit tests
2 parents 2747cee + 5924f23 commit e9bfa73

File tree

5 files changed

+180
-2
lines changed

5 files changed

+180
-2
lines changed

spec/branch_report_action_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
describe Fastlane::Actions::BranchReportAction do
2+
let (:action) { Fastlane::Actions::BranchReportAction }
3+
let (:command) { BranchIOCLI::Command::ReportCommand }
4+
5+
it 'provides the same options as the ReportCommand' do
6+
expect(action.available_options.map(&:key).sort).to eq command.available_options.map(&:name).sort
7+
end
8+
9+
it 'calls run!' do
10+
mock_command = double :command
11+
expect(mock_command).to receive(:run!)
12+
13+
expect(command).to receive(:new) { mock_command }
14+
15+
action.run({})
16+
end
17+
18+
it 'calls UI.user_error! on exception' do
19+
mock_command = double :command
20+
expect(mock_command).to receive(:run!).and_raise(RuntimeError)
21+
22+
expect(command).to receive(:new) { mock_command }
23+
24+
expect(FastlaneCore::UI).to receive(:user_error!)
25+
26+
action.run({})
27+
end
28+
29+
it 'is supported on iOS' do
30+
expect(action.is_supported?(:ios)).to be true
31+
end
32+
33+
it 'is in the :project category' do
34+
expect(action.category).to eq :project
35+
end
36+
37+
it 'renders the description template for details' do
38+
expect(action).to receive(:render).with(:report_description) { "rendered description" }
39+
expect(action.details).to eq "rendered description"
40+
end
41+
42+
it 'has a description' do
43+
expect(action.description).not_to be_blank
44+
end
45+
46+
it 'has authors' do
47+
expect(action.authors).not_to be_blank
48+
end
49+
50+
it 'has examples' do
51+
expect(action.example_code).not_to be_blank
52+
end
53+
end

spec/config_item_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
describe FastlaneCore::ConfigItem do
2+
it 'from_branch_option maps fields' do
3+
BranchOption = Struct.new :name, :env_name, :type, :default_value, :description
4+
5+
option = BranchOption.new :foo, "BRANCH_FOO", String, "bar", "A field called foo"
6+
7+
config_item = FastlaneCore::ConfigItem.from_branch_option option
8+
9+
expect(config_item.key).to eq :foo
10+
expect(config_item.env_name).to eq "BRANCH_FOO"
11+
expect(config_item.data_type).to be String
12+
expect(config_item.default_value).to eq "bar"
13+
expect(config_item.description).to eq "A field called foo"
14+
expect(config_item.optional).to be true
15+
end
16+
end

spec/setup_branch_action_spec.rb

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,59 @@
11
describe Fastlane::Actions::SetupBranchAction do
2-
# TODO: This
2+
let (:action) { Fastlane::Actions::SetupBranchAction }
3+
let (:command) { BranchIOCLI::Command::SetupCommand }
4+
5+
it 'provides the same options as the SetupCommand' do
6+
expect(action.available_options.map(&:key).sort).to eq command.available_options.map(&:name).sort
7+
end
8+
9+
it 'loads the Branchfile and calls run!' do
10+
mock_config = double :configuration
11+
expect(mock_config).to receive(:load_configuration_file).with("Branchfile")
12+
13+
mock_command = double :command
14+
expect(mock_command).to receive(:run!)
15+
16+
expect(command).to receive(:new) { mock_command }
17+
18+
action.run(mock_config)
19+
end
20+
21+
it 'calls UI.user_error! on exception' do
22+
mock_config = double :configuration
23+
expect(mock_config).to receive(:load_configuration_file).with("Branchfile")
24+
25+
mock_command = double :command
26+
expect(mock_command).to receive(:run!).and_raise(RuntimeError)
27+
28+
expect(command).to receive(:new) { mock_command }
29+
30+
expect(FastlaneCore::UI).to receive(:user_error!)
31+
32+
action.run(mock_config)
33+
end
34+
35+
it 'is supported on iOS' do
36+
expect(action.is_supported?(:ios)).to be true
37+
end
38+
39+
it 'is in the :project category' do
40+
expect(action.category).to eq :project
41+
end
42+
43+
it 'renders the description template for details' do
44+
expect(action).to receive(:render).with(:setup_description) { "rendered description" }
45+
expect(action.details).to eq "rendered description"
46+
end
47+
48+
it 'has a description' do
49+
expect(action.description).not_to be_blank
50+
end
51+
52+
it 'has authors' do
53+
expect(action.authors).not_to be_blank
54+
end
55+
56+
it 'has examples' do
57+
expect(action.example_code).not_to be_blank
58+
end
359
end

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'simplecov'
44
require 'rspec/simplecov'
55

6-
# SimpleCov.minimum_coverage 95
6+
SimpleCov.minimum_coverage 90
77
SimpleCov.start
88

99
# This module is only used to check the environment is currently a testing env
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
describe Fastlane::Actions::ValidateUniversalLinksAction do
2+
let (:action) { Fastlane::Actions::ValidateUniversalLinksAction }
3+
let (:command) { BranchIOCLI::Command::ValidateCommand }
4+
5+
it 'provides the same options as the ValidateCommand' do
6+
expect(action.available_options.map(&:key).sort).to eq command.available_options.map(&:name).sort
7+
end
8+
9+
it 'calls run!' do
10+
mock_command = double :command
11+
expect(mock_command).to receive(:run!)
12+
13+
expect(command).to receive(:new) { mock_command }
14+
15+
action.run({})
16+
end
17+
18+
it 'calls UI.user_error! on exception' do
19+
mock_command = double :command
20+
expect(mock_command).to receive(:run!).and_raise(RuntimeError)
21+
22+
expect(command).to receive(:new) { mock_command }
23+
24+
expect(FastlaneCore::UI).to receive(:user_error!)
25+
26+
action.run({})
27+
end
28+
29+
it 'is supported on iOS' do
30+
expect(action.is_supported?(:ios)).to be true
31+
end
32+
33+
it 'is in the :project category' do
34+
expect(action.category).to eq :project
35+
end
36+
37+
it 'renders the description template for details' do
38+
expect(action).to receive(:render).with(:validate_description) { "rendered description" }
39+
expect(action.details).to eq "rendered description"
40+
end
41+
42+
it 'has a description' do
43+
expect(action.description).not_to be_blank
44+
end
45+
46+
it 'has authors' do
47+
expect(action.authors).not_to be_blank
48+
end
49+
50+
it 'has examples' do
51+
expect(action.example_code).not_to be_blank
52+
end
53+
end

0 commit comments

Comments
 (0)