fix DatabaseCleaner.called_externally? to work on Windows.

This commit is contained in:
Micah Geisel 2020-04-03 10:26:26 -07:00 committed by Micah Geisel
parent 3f35961c64
commit 37ff1f22eb
2 changed files with 44 additions and 17 deletions

View file

@ -7,7 +7,7 @@ module DatabaseCleaner
module_function :deprecate
def called_externally?(file, caller)
file != caller.first.split(":").first
file != caller.first[/^(.+\.rb):\d+/, 1]
end
module_function :called_externally?

View file

@ -2,25 +2,52 @@ require "database_cleaner/deprecation"
RSpec.describe DatabaseCleaner do
describe ".called_externally?" do
let(:path) { "/home/DatabaseCleaner/database_cleaner/spec/database_cleaner/deprecation_spec.rb" }
context "on a posix filesystem" do
let(:path) { "/home/DatabaseCleaner/database_cleaner/spec/database_cleaner/deprecation_spec.rb" }
it "returns false if the supplied file is the first file in the backtrace" do
backtrace = [
"/home/DatabaseCleaner/database_cleaner/spec/database_cleaner/deprecation_spec.rb:9 in `it'",
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1954:in `load'",
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1954:in `load_spec_file_handling_errors'",
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1496:in `block in load_spec_files'",
]
expect(DatabaseCleaner.called_externally?(path, backtrace)).to eq false
it "returns false if the supplied file is the first file in the backtrace" do
backtrace = [
"/home/DatabaseCleaner/database_cleaner/spec/database_cleaner/deprecation_spec.rb:9 in `it'",
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1954:in `load'",
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1954:in `load_spec_file_handling_errors'",
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1496:in `block in load_spec_files'",
]
expect(DatabaseCleaner.called_externally?(path, backtrace)).to eq false
end
it "returns true if the supplied file is not the first file in the backtrace" do
backtrace = [
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1954:in `load'",
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1954:in `load_spec_file_handling_errors'",
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1496:in `block in load_spec_files'",
]
expect(DatabaseCleaner.called_externally?(path, backtrace)).to eq true
end
end
it "returns true if the supplied file is not the first file in the backtrace" do
backtrace = [
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1954:in `load'",
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1954:in `load_spec_file_handling_errors'",
"/home/DatabaseCleaner/lib/rspec/core/configuration.rb:1496:in `block in load_spec_files'",
]
expect(DatabaseCleaner.called_externally?(path, backtrace)).to eq true
context "on a windows filesystem" do
let(:path) { "C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/database_cleaner-1.8.3/lib/database_cleaner/base.rb" }
it "returns false if the supplied file is the first file in the backtrace" do
backtrace = [
"C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/database_cleaner-1.8.3/lib/database_cleaner/base.rb:34:in `strategy='",
"C:/Ruby25-x64/database_cleaner/spec/database_cleaner/deprecation_spec.rb:9 in `it'",
"C:/Ruby25-x64/lib/rspec/core/configuration.rb:1954:in `load'",
"C:/Ruby25-x64/lib/rspec/core/configuration.rb:1954:in `load_spec_file_handling_errors'",
"C:/Ruby25-x64/lib/rspec/core/configuration.rb:1496:in `block in load_spec_files'",
]
expect(DatabaseCleaner.called_externally?(path, backtrace)).to eq false
end
it "returns true if the supplied file is not the first file in the backtrace" do
backtrace = [
"C:/Ruby25-x64/database_cleaner/spec/database_cleaner/deprecation_spec.rb:9 in `it'",
"C:/Ruby25-x64/lib/rspec/core/configuration.rb:1954:in `load'",
"C:/Ruby25-x64/lib/rspec/core/configuration.rb:1954:in `load_spec_file_handling_errors'",
"C:/Ruby25-x64/lib/rspec/core/configuration.rb:1496:in `block in load_spec_files'",
]
expect(DatabaseCleaner.called_externally?(path, backtrace)).to eq true
end
end
end
end