Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor, removing more methods from the Runtime class and putting th…
…em into a delegator object (Runtime::ForProgrammingLanguages) that faces the programming languages. Now much easier to see the dependency from Programming Language -> Runtime / Support Code
- Loading branch information
Showing
4 changed files
with
92 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'forwardable' | ||
|
||
module Cucumber | ||
class Runtime | ||
# This is what a programming language will consider to be a runtime. | ||
# | ||
# It's a thin class that directs the handul of methods needed by the | ||
# programming languages to the right place. | ||
class ForProgrammingLanguages | ||
extend Forwardable | ||
|
||
def initialize(support_code, runtime) | ||
@support_code, @runtime = support_code, runtime | ||
end | ||
|
||
def_delegators :@runtime, | ||
:embed, | ||
:ask, | ||
:announce | ||
|
||
def_delegators :@support_code, | ||
:invoke_steps, | ||
:invoke, | ||
:load_programming_language | ||
|
||
# Returns a Cucumber::Ast::Table for +text_or_table+, which can either | ||
# be a String: | ||
# | ||
# table(%{ | ||
# | account | description | amount | | ||
# | INT-100 | Taxi | 114 | | ||
# | CUC-101 | Peeler | 22 | | ||
# }) | ||
# | ||
# or a 2D Array: | ||
# | ||
# table([ | ||
# %w{ account description amount }, | ||
# %w{ INT-100 Taxi 114 }, | ||
# %w{ CUC-101 Peeler 22 } | ||
# ]) | ||
# | ||
def table(text_or_table, file=nil, line_offset=0) | ||
if Array === text_or_table | ||
Ast::Table.new(text_or_table) | ||
else | ||
Ast::Table.parse(text_or_table, file, line_offset) | ||
end | ||
end | ||
|
||
# Returns a regular String for +string_with_triple_quotes+. Example: | ||
# | ||
# """ | ||
# hello | ||
# world | ||
# """ | ||
# | ||
# Is retured as: " hello\nworld" | ||
# | ||
def py_string(string_with_triple_quotes, file=nil, line_offset=0) | ||
Ast::PyString.parse(string_with_triple_quotes) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters