Skip to content

Commit

Permalink
refactor specs (improve descriptions entirely)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtsnjp committed Sep 28, 2018
1 parent 7c82cfa commit 151213c
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 69 deletions.
10 changes: 5 additions & 5 deletions spec/config_spec.rb
Expand Up @@ -6,7 +6,8 @@
c.include Helplers
end

RSpec.describe "Running Texdoc", :type => :aruba do
RSpec.describe "Configuration", :type => :aruba do
let(:stderr) { last_command_started.stderr.gsub("\r", "") }
let(:sample) { "texlive-en" }
let(:defaults) do
[
Expand All @@ -27,21 +28,20 @@
end

before(:all) { set_default_env }
let(:stderr) { last_command_started.stderr }

context "the simplest case" do
context "the default behavior" do
before(:each) { run_texdoc "-D", sample }
before(:each) { stop_all_commands }

it "configuration should set from built-in defaults at the first place" do
it "most items should be set from built-in defaults" do
defaults.each do |config|
expect(stderr).to include(
debug_line "config", "Setting \"#{config}\" from built-in defaults.")
end
end

if not OS.windows?
it "set lang from the OS locale (except Windows)" do
it 'item "lang" should be set from the OS locale (except Windows)' do
expect(stderr).to include(
debug_line "config", "Setting \"lang=en\" from operating system locale.")
end
Expand Down
37 changes: 25 additions & 12 deletions spec/errors_spec.rb
Expand Up @@ -5,38 +5,51 @@
c.include Helplers
end

RSpec.describe "Error case:", :type => :aruba do
RSpec.describe "Errors", :type => :aruba do
let(:stderr) { last_command_started.stderr.gsub("\r", "") }
let(:nonexist_pkg) { "never_never_existing_package_foooooooooo" }
let(:msg_not_found) do
<<~EXPECTED
Sorry, no documentation found for #{nonexist_pkg}.
If you are unsure about the name, try searching CTAN's TeX catalogue at
https://ctan.org/search.html#byDescription.
EXPECTED
end
let(:msg_usage) do
"Try `texdoc --help' for short help, `texdoc texdoc' for full manual."
end

before(:all) { set_default_env }
let(:stderr) { last_command_started.stderr }

context "running texdoc with no option nor argument" do
context "running without any option nor argument" do
before(:each) { run_texdoc }
before(:each) { stop_all_commands }

it do
it 'result in the "no action" error' do
expect(last_command_started).to have_exit_status(2)
expect(stderr).to include(error_line "No action specified.")
expect(stderr).to include(
error_line "Try `texdoc --help' for short help, `texdoc texdoc' for full manual.")
expect(stderr).to include(error_line msg_usage)
end
end

context "running texdoc --just-view without an argument" do
context 'execute action the "just view" without an argument' do
before(:each) { run_texdoc "--just-view" }
before(:each) { stop_all_commands }

it do
it 'result in the "missing file operand" error' do
expect(last_command_started).to have_exit_status(2)
expect(stderr).to include(error_line "Missing file operand to --just-view.")
expect(stderr).to include(
error_line "Try `texdoc --help' for short help, `texdoc texdoc' for full manual.")
expect(stderr).to include(error_line msg_usage)
end
end

context "when any document for input cannot be found" do
before(:each) { run_texdoc "never_never_existing_package_foooooooooo" }
before(:each) { run_texdoc nonexist_pkg }
before(:each) { stop_all_commands }

it { expect(last_command_started).to have_exit_status(3) }
it 'result in the "not found" error' do
expect(stderr).to include(msg_not_found)
expect(last_command_started).to have_exit_status(3)
end
end
end
2 changes: 1 addition & 1 deletion spec/files_spec.rb
Expand Up @@ -5,7 +5,7 @@
c.include Helplers
end

RSpec.describe "Showing files", :type => :aruba do
RSpec.describe 'The "files" action', :type => :aruba do
before(:all) { set_default_env }

context "with --files" do
Expand Down
20 changes: 13 additions & 7 deletions spec/fuzzy_search_spec.rb
Expand Up @@ -6,28 +6,34 @@
end

RSpec.describe "Fuzzy search", :type => :aruba do
let(:stderr) { last_command_started.stderr.gsub("\r", "") }
before(:all) { set_default_env }
let(:stderr) { last_command_started.stderr }

context "should not be performed if user input is right" do
context "if user input is right" do
before(:each) { run_texdoc "-v", "texlive-en" }
before(:each) { stop_all_commands }

it { expect(stderr).not_to include(info_line "Fuzzy search result: ") }
it "should not be performed" do
expect(stderr).not_to include(info_line "Fuzzy search result: ")
end
end

context "should be performed if fuzzy_level > 0" do
context "if fuzzy_level > 0" do
before(:each) { run_texdoc "-v -c fuzzy_level=1", "texlive-ex" }
before(:each) { stop_all_commands }

it { expect(stderr).to include(info_line "Fuzzy search result: ") }
it "should be performed" do
expect(stderr).to include(info_line "Fuzzy search result: ")
end
end

context "should not be performed if fuzzy_level = 0" do
context "if fuzzy_level = 0" do
before(:each) { run_texdoc "-v -c fuzzy_level=0", "texlive-ex" }
before(:each) { stop_all_commands }

it { expect(stderr).not_to include(info_line "Fuzzy search result: ") }
it "should not be performed" do
expect(stderr).not_to include(info_line "Fuzzy search result: ")
end
end

# TODO: check fuzzy search deliver the correct results
Expand Down
43 changes: 22 additions & 21 deletions spec/getopt_spec.rb
Expand Up @@ -5,19 +5,20 @@
c.include Helplers
end

RSpec.describe "Running Texdoc", :type => :aruba do
RSpec.describe "The command line option parser", :type => :aruba do
def set_cmo_line(config, opt)
debug_line "config", "Setting \"#{config}\" from command line option \"#{opt}\"."
debug_line "config",
"Setting \"#{config}\" from command line option \"#{opt}\"."
end

def ignore_cmo_line(config, opt)
debug_line "config", "Ignoring \"#{config}\" from command line option \"#{opt}\"."
debug_line "config",
"Ignoring \"#{config}\" from command line option \"#{opt}\"."
end

let(:stderr) { last_command_started.stderr.gsub("\r", "") }
let(:sample) { "texlive-en" }

before(:all) { set_default_env }
let(:stderr) { last_command_started.stderr }

context "with an argument" do
before(:each) { run_texdoc sample }
Expand All @@ -26,51 +27,51 @@ def ignore_cmo_line(config, opt)
it { expect(last_command_started).to be_successfully_executed }
end

context 'with option "-D"' do
context "with -D" do
before(:each) { run_texdoc "-D", sample }
before(:each) { stop_all_commands }

it do
it "should activate all debug items" do
expect(last_command_started).to be_successfully_executed
expect(stderr).to include(set_cmo_line "debug_list=all", "-D")
end
end

context 'with option "--debug"' do
context "with --debug" do
before(:each) { run_texdoc "--debug", sample }
before(:each) { stop_all_commands }

it do
it "should activate all debug items" do
expect(last_command_started).to be_successfully_executed
expect(stderr).to include(set_cmo_line "debug_list=all", "--debug")
end
end

context 'with option "-dconfig"' do
context "with -dconfig" do
before(:each) { run_texdoc "-dconfig", sample }
before(:each) { stop_all_commands }

it do
it 'should activate only debug item "config"' do
expect(last_command_started).to be_successfully_executed
expect(stderr).to include(set_cmo_line "debug_list=config", "-d")
end
end

context 'with option "--debug=config"' do
context "with --debug=config" do
before(:each) { run_texdoc "--debug=config", sample }
before(:each) { stop_all_commands }

it do
it 'should activate only debug item "config"' do
expect(last_command_started).to be_successfully_executed
expect(stderr).to include(set_cmo_line "debug_list=config", "--debug")
end
end

context 'with option "-dconfig -lIv"' do
context "with -dconfig -lIv" do
before(:each) { run_texdoc "-dconfig", "-lIv", sample }
before(:each) { stop_all_commands }

it do
it "all specified options should effective" do
expect(last_command_started).to be_successfully_executed
expect(stderr).to include(set_cmo_line "debug_list=config", "-d")
expect(stderr).to include(set_cmo_line "mode=list", "-l")
Expand All @@ -79,11 +80,11 @@ def ignore_cmo_line(config, opt)
end
end

context 'with option "-dconfig -wmls"' do
context "with -dconfig -wmls" do
before(:each) { run_texdoc "-dconfig", "-wmls", sample }
before(:each) { stop_all_commands }

it do
it "only -w should effective and others should not" do
expect(last_command_started).to be_successfully_executed
expect(stderr).to include(set_cmo_line "mode=view", "-w")
expect(stderr).to include(ignore_cmo_line "mode=mixed", "-m")
Expand All @@ -92,23 +93,23 @@ def ignore_cmo_line(config, opt)
end
end

context 'with option "-D -Mdconfig"' do
context "with -D -Mdconfig" do
before(:each) { run_texdoc "-D", "-Mdconfig", sample }
before(:each) { stop_all_commands }

it do
it "-w and -M should effective, and -d should not" do
expect(last_command_started).to be_successfully_executed
expect(stderr).to include(set_cmo_line "debug_list=all", "-D")
expect(stderr).to include(set_cmo_line "machine_switch=true", "-M")
expect(stderr).to include(ignore_cmo_line "debug_list=config", "-d")
end
end

context 'with option "-D -c fuzzy_level=0 -qv"' do
context "with -D -c fuzzy_level=0 -qv" do
before(:each) { run_texdoc "-D", "-c fuzzy_level=0", "-qv", sample }
before(:each) { stop_all_commands }

it do
it "-c and -q should effective, and -v should not" do
expect(last_command_started).to be_successfully_executed
expect(stderr).to include(set_cmo_line "fuzzy_level=0", "-c")
expect(stderr).to include(set_cmo_line "verbosity_level=0", "-q")
Expand Down
10 changes: 5 additions & 5 deletions spec/help_spec.rb
Expand Up @@ -5,7 +5,8 @@
c.include Helplers
end

RSpec.describe "Showing help", :type => :aruba do
RSpec.describe 'The "help" action', :type => :aruba do
let(:stdout) { last_command_started.stdout.gsub("\r", "") }
let(:help_text) do
<<~EXPECTED
Usage: texdoc [OPTION...] NAME...
Expand Down Expand Up @@ -46,15 +47,14 @@
end

before(:all) { set_default_env }
let(:stdout) { last_command_started.stdout.gsub("\r", "") }

context "with --help" do
before(:each) { run_texdoc "--help" }
before(:each) { stop_all_commands }

it do
expect(last_command_started).to be_successfully_executed
expect(stdout).to eq help_text
expect(last_command_started).to be_successfully_executed
end
end

Expand All @@ -63,8 +63,8 @@
before(:each) { stop_all_commands }

it do
expect(last_command_started).to be_successfully_executed
expect(stdout).to eq help_text
expect(last_command_started).to be_successfully_executed
end
end

Expand All @@ -73,8 +73,8 @@
before(:each) { stop_all_commands }

it do
expect(last_command_started).to be_successfully_executed
expect(stdout).to eq help_text
expect(last_command_started).to be_successfully_executed
end
end
end
15 changes: 9 additions & 6 deletions spec/verbose_spec.rb
Expand Up @@ -6,17 +6,20 @@
end

RSpec.describe "Verbose outputs", :type => :aruba do
before(:all) { set_default_env }
let(:stderr) { last_command_started.stderr.gsub("\r", "") }

context 'ordinally show "view command" and "setting env"' do
before(:each) { run_texdoc "-v", "texdoc" }
before(:all) { set_default_env }

context "with normal input" do
before(:each) { run_texdoc "-v", "texlive-en" }
before(:each) { stop_all_commands }

it do
it 'should include "view command" and "env" info' do
info_viewcmd = info_line "View command: .+"
info_env = info_line "Setting environment LC_CTYPE to: .+"
expect(stderr).to match(Regexp.new(
"^" + info_viewcmd + '\n' + info_env + '\Z'))
expect(last_command_started).to be_successfully_executed
expect(stderr).to match(
/^texdoc info: View command: .+\ntexdoc info: Setting environment LC_CTYPE to: .+\Z/)
end
end
end

0 comments on commit 151213c

Please sign in to comment.