Sha256: ba404c57edba906138a5dedc03b7c182dd883f2cc326a278388956d8c282efa1

Contents?: true

Size: 1.74 KB

Versions: 62

Compression:

Stored size: 1.74 KB

Contents

# FakeFS::SpecHelpers provides a simple macro for RSpec example
# groups to turn FakeFS on and off.
# To use it simply require 'fakefs/spec_helpers', then include
# FakeFS::SpecHelpers into any example groups that you wish
# to use FakeFS in. For example:
#
#   require 'fakefs/spec_helpers'
#
#   describe "Some specs that deal with files" do
#     include FakeFS::SpecHelpers
#     ...
#   end
#
# By default, including FakeFS::SpecHelpers will run for each
# example inside a describe block.
# If you want to turn on FakeFS one time only for all your examples,
# you will need to include FakeFS::SpecHelpers::All.
#
# Alternatively, you can include FakeFS::SpecHelpers in all your
# example groups using RSpec's configuration block in
# your spec helper:
#
#   require 'fakefs/spec_helpers'
#
#   RSpec.configure do |config|
#     config.include FakeFS::SpecHelpers
#   end
#
# If you do the above then use_fakefs will be available in all of
# your example groups.
#
require 'fakefs/safe'

# FakeFS module
module FakeFS
  def use_fakefs(describe_block, opts)
    describe_block.before opts[:with] do
      FakeFS.activate!
    end

    describe_block.after opts[:with] do
      FakeFS.deactivate!
      FakeFS::FileSystem.clear if opts[:with] == :each
    end
  end

  # Module SpecHelpers
  module SpecHelpers
    include ::FakeFS

    def self.extended(example_group)
      example_group.use_fakefs(example_group, with: :each)
    end

    def self.included(example_group)
      example_group.extend self
    end

    # Module All
    module All
      include ::FakeFS

      def self.extended(example_group)
        example_group.use_fakefs(example_group, with: :all)
      end

      def self.included(example_group)
        example_group.extend self
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
fakefs-2.5.0 lib/fakefs/spec_helpers.rb
fakefs-2.4.0 lib/fakefs/spec_helpers.rb
fakefs-2.3.0 lib/fakefs/spec_helpers.rb
fakefs-2.2.0 lib/fakefs/spec_helpers.rb
fakefs-2.1.0 lib/fakefs/spec_helpers.rb
fakefs-2.0.0 lib/fakefs/spec_helpers.rb
fakefs-1.9.0 lib/fakefs/spec_helpers.rb
fakefs-1.8.0 lib/fakefs/spec_helpers.rb
fakefs-1.7.0 lib/fakefs/spec_helpers.rb
fakefs-1.6.0 lib/fakefs/spec_helpers.rb
fakefs-1.5.1 lib/fakefs/spec_helpers.rb
fakefs-1.5.0 lib/fakefs/spec_helpers.rb
fakefs-1.4.1 lib/fakefs/spec_helpers.rb
fakefs-1.4.0 lib/fakefs/spec_helpers.rb
fakefs-1.3.2 lib/fakefs/spec_helpers.rb
fakefs-1.3.1 lib/fakefs/spec_helpers.rb
fakefs-1.3.0 lib/fakefs/spec_helpers.rb
fakefs-1.2.3 lib/fakefs/spec_helpers.rb
fakefs-1.2.2 lib/fakefs/spec_helpers.rb
fakefs-1.2.1 lib/fakefs/spec_helpers.rb