Module: NullDB::RSpec::NullifiedDatabase
- Defined in:
- lib/nulldb_rspec.rb
Defined Under Namespace
Classes: HaveExecuted
Constant Summary collapse
- NullDBAdapter =
ActiveRecord::ConnectionAdapters::NullDBAdapter
Class Method Summary collapse
- .contextually_nullify_database(context) ⇒ Object
- .globally_nullify_database ⇒ Object
- .included(other) ⇒ Object
- .nullify_contextually?(other) ⇒ Boolean
- .nullify_database(receiver) ⇒ Object
Instance Method Summary collapse
-
#have_executed(entry_point) ⇒ Object
A matcher for asserting that database statements have (or have not) been executed.
Class Method Details
.contextually_nullify_database(context) ⇒ Object
48 49 50 |
# File 'lib/nulldb_rspec.rb', line 48 def self.contextually_nullify_database(context) nullify_database(context) end |
.globally_nullify_database ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/nulldb_rspec.rb', line 39 def self.globally_nullify_database block = lambda { |config| nullify_database(config) } if defined?(RSpec) RSpec.configure(&block) else Spec::Runner.configure(&block) end end |
.included(other) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/nulldb_rspec.rb', line 75 def self.included(other) if nullify_contextually?(other) contextually_nullify_database(other) else globally_nullify_database end end |
.nullify_contextually?(other) ⇒ Boolean
83 84 85 86 87 88 89 |
# File 'lib/nulldb_rspec.rb', line 83 def self.nullify_contextually?(other) if defined?(RSpec) other < RSpec::Core::ExampleGroup else other.is_a? Spec::ExampleGroup end end |
.nullify_database(receiver) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/nulldb_rspec.rb', line 91 def self.nullify_database(receiver) receiver.before :all do ActiveRecord::Base.establish_connection(:adapter => :nulldb) end receiver.before :each do ActiveRecord::Base.connection.checkpoint! end receiver.after :all do ActiveRecord::Base.establish_connection(:test) end end |
Instance Method Details
#have_executed(entry_point) ⇒ Object
A matcher for asserting that database statements have (or have not) been executed. Usage:
ActiveRecord::Base.connection.should have_executed(:insert)
The types of statement that can be matched mostly mirror the public operations available in ActiveRecord::ConnectionAdapters::DatabaseStatements:
-
:select_one
-
:select_all
-
:select_value
-
:insert
-
:update
-
:delete
-
:execute
There is also a special :anything symbol that will match any operation.
69 70 71 |
# File 'lib/nulldb_rspec.rb', line 69 def have_executed(entry_point) HaveExecuted.new(entry_point) end |