Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/knapsack/adapters/minitest_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def set_test_helper_path(file_path)

def self.test_path(obj)
# Pick the first public method in the class itself, that starts with "test_"
test_method_name = obj.public_methods(false).select{|m| m =~ /^test_/ }.first
test_method_name = obj.public_methods(false).select{|m| m =~ /^test(:|_)/ }.first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you use the previous version of the code with /^test_/ then test for shoulda-context still passes. It should fail.

method_object = obj.method(test_method_name)
full_test_path = method_object.source_location.first
parent_of_test_dir_regexp = Regexp.new("^#{@@parent_of_test_dir}")
Expand Down
22 changes: 22 additions & 0 deletions spec/knapsack/adapters/minitest_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,26 @@ def name

it { should eq './spec/knapsack/adapters/minitest_adapter_spec.rb' }
end

describe 'shoulda context installed' do
class FakeUserTest
def test_user_age; end

def name
"test_: on delete qqq should allow us to make another portfolio for that user. "
end
end

let(:obj) { FakeUserTest.new }

subject { described_class.test_path(obj) }

before do
parent_of_test_dir = File.expand_path('../../../', File.dirname(__FILE__))
parent_of_test_dir_regexp = Regexp.new("^#{parent_of_test_dir}")
described_class.class_variable_set(:@@parent_of_test_dir, parent_of_test_dir_regexp)
end

it { should eq './spec/knapsack/adapters/minitest_adapter_spec.rb' }
end
end