philoserf / Aruba / Docs / 03 testing frameworks / Rspec
Announce information during rspec run
In order to make debugging easier As a developer using RSpec I want to have certain information announced
Background:
- Given I use a fixture named "
cli-app"
Scenario: Announce change of directory
- Given a file named "
spec/announcing_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Announce', type: :aruba do specify "run command", :announce_directory do create_directory "dir.d" cd "dir.d" end end - When I run `rspec`
- Then the specs should all pass
- And the output should contain:
text
$ cd / - And the output should match:
text
tmp\/aruba-[^\/]+\/dir.d
Scenario: Announce stdout
- Given an executable named "
bin/aruba-test-cli" with:bash#!/usr/bin/env bash echo 'Hello World' - And a file named "
spec/announcing_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Announce', type: :aruba do specify "run command", :announce_stdout do run_command_and_stop "aruba-test-cli" expect(last_command_stopped).to be_successfully_executed end end - When I run `rspec`
- Then the specs should all pass
- And the output should contain:
text
<<-STDOUT Hello World STDOUT
Scenario: Announce stderr
- Given an executable named "
bin/aruba-test-cli" with:bash#!/usr/bin/env bash echo 'Hello World' >&2 - And a file named "
spec/announcing_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Announce', type: :aruba do specify "run command", :announce_stderr do run_command_and_stop "aruba-test-cli" expect(last_command_stopped).to be_successfully_executed end end - When I run `rspec`
- Then the specs should all pass
- And the output should contain:
text
<<-STDERR Hello World STDERR
Scenario: Announce both stderr and stdout
- Given an executable named "
bin/aruba-test-cli" with:bash#!/usr/bin/env bash echo 'Hello' >&2 echo 'World' - And a file named "
spec/announcing_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Announce', type: :aruba do specify "run command", :announce_output do run_command_and_stop "aruba-test-cli" expect(last_command_stopped).to be_successfully_executed end end - When I run `rspec`
- Then the specs should all pass
- And the output should contain:
text
<<-STDERR Hello STDERR - And the output should contain:
text
<<-STDOUT World STDOUT
Scenario: Announce command
- Given an executable named "
bin/aruba-test-cli" with:bash#!/usr/bin/env bash echo 'Hello World' - And a file named "
spec/announcing_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Announce', type: :aruba do specify "run command", :announce_command do run_command_and_stop "aruba-test-cli" expect(last_command_stopped).to be_successfully_executed end end - When I run `rspec`
- Then the specs should all pass
- And the output should contain:
text
$ aruba-test-cli
Scenario: Announce change of environment variable
- Given an executable named "
bin/aruba-test-cli" with:bash#!/usr/bin/env bash echo 'Hello World' - And a file named "
spec/announcing_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Announce', type: :aruba do specify "run command", :announce_changed_environment do set_environment_variable("MY_VAR", "my_value") run_command_and_stop "aruba-test-cli" expect(last_command_stopped).to be_successfully_executed end end - When I run `rspec`
- Then the specs should all pass
- And the output should contain:
text
$ export MY_VAR=my_value
Scenario: Announce file system status of command
This will output information like owner, group, atime, mtime, ctime, size, mode and if command is executable.
- Given an executable named "
bin/aruba-test-cli" with:bash#!/usr/bin/env bash echo 'Hello World' - And a file named "
spec/announcing_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Announce', type: :aruba do specify "run command", :announce_command_filesystem_status do run_command_and_stop "aruba-test-cli" expect(last_command_stopped).to be_successfully_executed end end - When I run `rspec`
- Then the specs should all pass
- And the output should contain:
text
# mode => 755 - And the output should contain:
text
# owner - And the output should contain:
text
# group - And the output should contain:
text
# ctime - And the output should contain:
text
# mtime - And the output should contain:
text
# atime - And the output should contain:
text
# size - And the output should contain:
text
# executable
Scenario: Announce content of command
This will output the content of the executable command. This hook should be used with scripts only. For binary executables, to prevent large garbage output, a short replacement message is displayed.
- Given an executable named "
bin/aruba-test-cli" with:bash#!/usr/bin/env bash echo 'Hello World' - And a file named "
spec/announcing_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Announce', type: :aruba do specify "run command", :announce_command_content do run_command_and_stop "aruba-test-cli" expect(last_command_stopped).to be_successfully_executed end end - When I run `rspec`
- Then the specs should all pass
- And the output should contain:
text
#!/usr/bin/env bash echo 'Hello World'
Scenario: Announce everything
- Given an executable named "
bin/aruba-test-cli" with:bash#!/usr/bin/env bash echo 'Hello World' - And a file named "
spec/announcing_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Announce', type: :aruba do specify "run command", :announce do run_command_and_stop "aruba-test-cli" expect(last_command_stopped).to be_successfully_executed end end - When I run `rspec`
- Then the specs should all pass
- And the output should contain:
text
<<-STDOUT Hello World STDOUT - And the output should contain:
text
<<-STDERR STDERR - And the output should contain:
text
<<-COMMAND #!/usr/bin/env bash echo 'Hello World' COMMAND - And the output should contain:
text
<<-COMMAND FILESYSTEM STATUS
Source: features/03_testing_frameworks/rspec/announce_information_for_troubleshooting.feature at commit c39310a7, Aruba (MIT license).