Class: QED::Context
- Inherits:
-
Module
- Object
- Module
- QED::Context
- Defined in:
- lib/qed/script.rb
Instance Method Summary collapse
- #_binding ⇒ Object
-
#after(&f) ⇒ Object
Set after step.
-
#before(&f) ⇒ Object
Set before step.
- #fixture(fname, content = nil) ⇒ Object
-
#initialize(script) ⇒ Context
constructor
A new instance of Context.
-
#table(file = nil, &blk) ⇒ Object
Table-based steps.
Constructor Details
#initialize(script) ⇒ Context
Returns a new instance of Context.
131 132 133 |
# File 'lib/qed/script.rb', line 131 def initialize(script) @_script = script end |
Instance Method Details
#_binding ⇒ Object
135 136 137 |
# File 'lib/qed/script.rb', line 135 def _binding @_binding ||= binding end |
#after(&f) ⇒ Object
Set after step.
146 147 148 149 |
# File 'lib/qed/script.rb', line 146 def after(&f) @_after = f if f @_after end |
#before(&f) ⇒ Object
Set before step.
140 141 142 143 |
# File 'lib/qed/script.rb', line 140 def before(&f) @_before = f if f @_before end |
#fixture(fname, content = nil) ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/qed/script.rb', line 171 def fixture(fname, content=nil) raise if File.directory?(fname) if content FileUtils.mkdir_p(File.dirname(fname)) File.open(fname, 'w'){ |f| f << content } else raise LoadError, "no such fixture file -- #{fname}" unless File.exist?(fname) File.read(fname) end end |
#table(file = nil, &blk) ⇒ Object
Table-based steps.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/qed/script.rb', line 152 def table(file=nil, &blk) require 'yaml' file ||= File.basename(@_script.file).chomp(File.extname(@_script.file)) + '.yaml' Dir.ascend(Dir.pwd) do |path| f1 = File.join(path, file) f2 = File.join(path, 'fixtures', file) fr = File.file?(f1) ? f1 : File.exist?(f2) ? f2 : nil (file = fr; break) if fr end tbl = YAML.load(File.new(file)) tbl.each do |set| @_script.run_step(set.to_yaml.tabto(2)){ blk.call(set) } #@_script.output.report_table(set) end end |