Module: Gemika::RSpec
Instance Method Summary collapse
-
#binary(options = {}) ⇒ Object
Returns the binary name for the current RSpec version.
-
#configure(&block) ⇒ Object
Configures RSpec.
-
#configure_clean_database_before_example ⇒ Object
Configures RSpec to clean out the database before each example.
-
#configure_should_syntax ⇒ Object
Configures RSpec so it allows the
should
syntax that works across all RSpec versions. -
#run_specs(options = nil) ⇒ Object
Runs the RSpec binary.
Instance Method Details
#binary(options = {}) ⇒ Object
Returns the binary name for the current RSpec version.
33 34 35 36 37 38 39 |
# File 'lib/gemika/rspec.rb', line 33 def binary( = {}) if Env.gem?('rspec', '< 2', ) 'spec' else 'rspec' end end |
#configure(&block) ⇒ Object
Configures RSpec.
Works with both RSpec 1 and RSpec 2.
46 47 48 |
# File 'lib/gemika/rspec.rb', line 46 def configure(&block) configurator.configure(&block) end |
#configure_clean_database_before_example ⇒ Object
Configures RSpec to clean out the database before each example.
Requires the database_cleaner
gem to be added to your development dependencies.
55 56 57 58 59 60 61 62 63 |
# File 'lib/gemika/rspec.rb', line 55 def configure_clean_database_before_example require 'database_cleaner' # optional dependency configure do |config| config.before(:each) do # Truncation works across most database adapters; I had issues with :deletion and pg DatabaseCleaner.clean_with(:truncation) end end end |
#configure_should_syntax ⇒ Object
Configures RSpec so it allows the should
syntax that works across all RSpec versions.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gemika/rspec.rb', line 68 def configure_should_syntax if Env.gem?('rspec', '>= 2.11') configure do |config| config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] } config.mock_with(:rspec) { |c| c.syntax = [:should, :expect] } end else # We have an old RSpec that only understands should syntax end end |
#run_specs(options = nil) ⇒ Object
Runs the RSpec binary.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gemika/rspec.rb', line 10 def run_specs( = nil) ||= {} files = .fetch(:files, 'spec') = .fetch(:options, '--color') # We need to override the gemfile explicitely, since we have a default Gemfile in the project root gemfile = .fetch(:gemfile, Gemika::Env.gemfile) fatal = .fetch(:fatal, true) runner = binary(:gemfile => gemfile) bundle_exec = .fetch(:bundle_exec) ? 'bundle exec' : nil command = [bundle_exec, runner, , files].compact.join(' ') result = shell_out(command) if result true elsif fatal raise RSpecFailed, "RSpec failed: #{command}" else false end end |