Class: Tack::Adapters::RSpecAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/tack/adapters/rspec_adapter.rb

Instance Method Summary collapse

Instance Method Details

#run(file, test) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'lib/tack/adapters/rspec_adapter.rb', line 92

def run(file, test)
  Spec::Runner.options.instance_variable_set(:@examples, [test])
  Spec::Runner.options.instance_variable_set(:@example_groups, [])
  Spec::Runner.options.instance_variable_set(:@files, [file])
  Spec::Runner.options.instance_variable_set(:@files_loaded, false)
  formatter = Spec::Runner::Formatter::TackFormatter.new(Spec::Runner.options.formatter_options)
  Spec::Runner.options.instance_variable_set(:@formatters, [formatter])
  Spec::Runner.options.run_examples
  formatter.results
end

#tests_for(file, pattern) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/tack/adapters/rspec_adapter.rb', line 78

def tests_for(file, pattern)
  Spec::Runner.options.instance_variable_set(:@formatters, [Spec::Runner::Formatter::TackFormatter.new(Spec::Runner.options.formatter_options)])
  Spec::Runner.options.instance_variable_set(:@example_groups, [])
  Spec::Runner.options.instance_variable_set(:@files, [file])
  Spec::Runner.options.instance_variable_set(:@files_loaded, false)
  runner = Spec::Runner::ExampleGroupRunner.new(Spec::Runner.options)
  runner.load_files([file])
  example_groups = runner.send(:example_groups)
  examples = example_groups.inject([]) do |arr, group|
    arr += group.examples
  end
  examples.map {|example| [file, example.description]}.select {|file,description| description.match(pattern)}
end