Module: AllureRubyApi::DSL

Defined in:
lib/allure-ruby-api/dsl.rb

Instance Method Summary collapse

Instance Method Details

#attach_file(title, file, mime_type = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/allure-ruby-api/dsl.rb', line 15

def attach_file(title, file, mime_type = nil)
  step = current_step
  dir = Pathname.new(AllureRSpec::Config.output_dir)
  FileUtils.mkdir_p(dir)
  file_extname = File.extname(file.path.downcase)
  mime_type ||= MimeMagic.by_path(file.path) || "text/plain"
  attachment = dir.join("#{Digest::SHA256.file(file.path).hexdigest}-attachment#{(file_extname.empty?) ? '' : file_extname}")
  FileUtils.cp(file.path, attachment)
  suite = self.example.[:example_group][:description_args].first
  test = self.example.[:description]
  AllureRubyApi::Builder.add_attachment(suite, test, {
      :type => type,
      :title => title,
      :source => attachment.basename,
      :size => File.stat(attachment).size
  }, step)
end

#step(step, &block) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/allure-ruby-api/dsl.rb', line 7

def step(step, &block)
  suite = self.example.[:example_group][:description_args].first
  test = self.example.[:description]
  AllureRSpec::Builder.start_step(suite, test, step)
  __with_step step, &block
  AllureRSpec::Builder.stop_step(suite, test, step)
end