Class: Miniswen::Testing::FakeEnv
- Inherits:
-
Object
- Object
- Miniswen::Testing::FakeEnv
- Defined in:
- lib/miniswen/testing.rb
Overview
A shell made of a Hash. echo behaves like echo, so the submit marker
works the way it does in a real sandbox; anything else is looked up.
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
-
#exec(command, timeout: nil, env: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#initialize(canned = {}) ⇒ FakeEnv
constructor
A new instance of FakeEnv.
- #on(command, output, exit_code: 0) ⇒ Object
Constructor Details
#initialize(canned = {}) ⇒ FakeEnv
Returns a new instance of FakeEnv.
57 58 59 60 |
# File 'lib/miniswen/testing.rb', line 57 def initialize(canned = {}) @canned = canned @commands = [] end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
55 56 57 |
# File 'lib/miniswen/testing.rb', line 55 def commands @commands end |
Instance Method Details
#exec(command, timeout: nil, env: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
66 67 68 69 70 71 72 |
# File 'lib/miniswen/testing.rb', line 66 def exec(command, timeout: nil, env: nil) # rubocop:disable Lint/UnusedMethodArgument @commands << command return result(0, command.delete_prefix("echo ")) if command.start_with?("echo ") exit_code, output = @canned.fetch(command, [0, ""]) result(exit_code, output) end |
#on(command, output, exit_code: 0) ⇒ Object
62 63 64 |
# File 'lib/miniswen/testing.rb', line 62 def on(command, output, exit_code: 0) @canned[command] = [exit_code, output] end |