Skip to content

Commit

Permalink
fix DatabaseCleaner.called_externally? to work on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
botandrose-machine authored and botandrose committed Apr 4, 2020
1 parent 3f35961 commit 37ff1f2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/database_cleaner/deprecation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def deprecate message
module_function :deprecate

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

Expand Down
59 changes: 43 additions & 16 deletions spec/database_cleaner/deprecation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,52 @@

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

0 comments on commit 37ff1f2

Please sign in to comment.