class Rspec::Core::Configuration
def after(each_or_all=:each, options={}, &block)
def after(each_or_all=:each, options={}, &block) @hooks[:after][each_or_all] << [options, block] end
def alias_example_to(new_name, extra_options={})
E.g. alias_example_to :crazy_slow, :speed => 'crazy_slow' defines
def alias_example_to(new_name, extra_options={}) Rspec::Core::ExampleGroup.alias_example_to(new_name, extra_options) end
def backtrace_clean_patterns
def backtrace_clean_patterns @options[:backtrace_clean_patterns] end
def before(each_or_all=:each, options={}, &block)
def before(each_or_all=:each, options={}, &block) @hooks[:before][each_or_all] << [options, block] end
def cleaned_from_backtrace?(line)
def cleaned_from_backtrace?(line) @options[:backtrace_clean_patterns].any? { |regex| line =~ regex } end
def color_enabled=(on_or_off)
def color_enabled=(on_or_off) @options[:color_enabled] = on_or_off end
def color_enabled?
def color_enabled? @options[:color_enabled] end
def configure_mock_framework
def configure_mock_framework require_mock_framework_adapter Rspec::Core::ExampleGroup.send(:include, Rspec::Core::MockFrameworkAdapter) end
def debug=(bool)
def debug=(bool) return unless bool begin require 'ruby-debug' rescue LoadError raise <<-EOM 50} st install ruby-debug to run rspec with the --debug option. have ruby-debug installed as a ruby gem, then you need to either e 'rubygems' or configure the RUBYOPT environment variable with lue 'rubygems'. 50} end end
def default_options
def default_options { :color_enabled => false, :mock_framework => nil, :use_transactional_examples => true, :profile_examples => false, :files_to_run => [], :filename_pattern => '**/*_spec.rb', :formatter_class => Rspec::Core::Formatters::ProgressFormatter, :backtrace_clean_patterns => [/\/lib\/ruby\//, /bin\/rcov:/, /vendor\/rails/, /bin\/rspec/, /bin\/spec/, /lib\/rspec\/(core|expectations|matchers|mocks)/] } end
def extend(mod, options={})
def extend(mod, options={}) @include_or_extend_modules << [:extend, mod, options] end
def filename_pattern
def filename_pattern @options[:filename_pattern] end
def filename_pattern=(new_pattern)
def filename_pattern=(new_pattern) @options[:filename_pattern] = new_pattern end
def files_or_directories_to_run=(*files)
def files_or_directories_to_run=(*files) @options[:files_to_run] = files.flatten.inject([]) do |result, file| if File.directory?(file) filename_pattern.split(",").each do |pattern| result += Dir["#{file}/#{pattern.strip}"] end else path, line_number = file.split(':') self.line_number = line_number if line_number result << path end result end end
def files_to_run
def files_to_run @options[:files_to_run] end
def filter_run(options={})
def filter_run(options={}) @filter = options unless @filter and @filter[:line_number] || @filter[:full_description] end
def find_hook(hook, each_or_all, group)
def find_hook(hook, each_or_all, group) @hooks[hook][each_or_all].select do |filters, block| group.all_apply?(filters) end.map { |filters, block| block } end
def find_modules(group)
def find_modules(group) @include_or_extend_modules.select do |include_or_extend, mod, filters| group.all_apply?(filters) end end
def formatter
def formatter @formatter ||= formatter_class.new end
def formatter=(formatter_to_use)
def formatter=(formatter_to_use) formatter_class = case formatter_to_use.to_s when 'd', 'doc', 'documentation', 's', 'n', 'spec', 'nested' Rspec::Core::Formatters::DocumentationFormatter when 'progress' Rspec::Core::Formatters::ProgressFormatter else raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?." end @options[:formatter_class] = formatter_class end
def formatter_class
def formatter_class @options[:formatter_class] end
def full_backtrace=(bool)
def full_backtrace=(bool) @options[:backtrace_clean_patterns].clear end
def full_description=(description)
def full_description=(description) filter_run :full_description => /#{description}/ end
def include(mod, options={})
def include(mod, options={}) @include_or_extend_modules << [:include, mod, options] end
def initialize
def initialize @run_all_when_everything_filtered = false @hooks = { :before => { :each => [], :all => [], :suite => [] }, :after => { :each => [], :all => [], :suite => [] } } @include_or_extend_modules = [] @filter, @exclusion_filter = nil, nil @options = default_options end
def libs=(libs)
def libs=(libs) libs.map {|lib| $LOAD_PATH.unshift lib} end
def line_number=(line_number)
def line_number=(line_number) filter_run :line_number => line_number.to_i end
def mock_framework=(use_me_to_mock)
def mock_framework=(use_me_to_mock) @options[:mock_framework] = use_me_to_mock end
def mock_with(use_me_to_mock)
def mock_with(use_me_to_mock) self.mock_framework = use_me_to_mock end
def output
def output $stdout end
def profile_examples
def profile_examples @options[:profile_examples] end
def profile_examples=(on_or_off)
def profile_examples=(on_or_off) @options[:profile_examples] = on_or_off end
def puts(msg="")
def puts(msg="") output.puts(msg) end
def require_files_to_run
def require_files_to_run files_to_run.map {|f| require f } end
def require_mock_framework_adapter
def require_mock_framework_adapter require case @options[:mock_framework].to_s when "", /rspec/i 'rspec/core/mocking/with_rspec' when /mocha/i 'rspec/core/mocking/with_mocha' when /rr/i 'rspec/core/mocking/with_rr' when /flexmock/i 'rspec/core/mocking/with_flexmock' else 'rspec/core/mocking/with_absolutely_nothing' end end
def run_all_when_everything_filtered?
def run_all_when_everything_filtered? @run_all_when_everything_filtered end
def use_transactional_examples=(value)
def use_transactional_examples=(value) @options[:use_transactional_examples] = value end
def use_transactional_examples?
def use_transactional_examples? @options[:use_transactional_examples] end