spec/api_spec.rb in method_log-0.0.6 vs spec/api_spec.rb in method_log-0.0.7

- old
+ new

@@ -47,15 +47,14 @@ + # implementation 2 end })) end - it 'finds method which is defined, then removed, and then defined again' do + it 'finds significant commits for definition of method' do repository = Repository.new(repository_path) commit_1 = repository.commit(source(path: 'foo.rb', source: %{ class Foo - def bar; end end })) commit_2 = repository.commit(source(path: 'foo.rb', source: %{ class Foo end @@ -68,24 +67,75 @@ commit_4 = repository.commit(source(path: 'foo.rb', source: %{ class Foo def bar; end end })) + commit_5 = repository.commit(source(path: 'foo.rb', source: %{ + class Foo + def bar + # implementation + end + end + })) method_commits, method_diffs = commits_and_diffs_for('Foo#bar') + expect(method_commits.map(&:sha)).to eq([commit_5.sha, commit_3.sha]) + end + + it 'continues past lastest introduction of method if required' do + repository = Repository.new(repository_path) + commit_1 = repository.commit(source(path: 'foo.rb', source: %{ + class Foo + def bar; end + end + })) + commit_2 = repository.commit(source(path: 'foo.rb', source: %{ + class Foo + end + })) + commit_3 = repository.commit(source(path: 'foo.rb', source: %{ + class Foo + def bar; end + end + })) + + method_commits, method_diffs = commits_and_diffs_for('Foo#bar', stop_at_latest_introduction_of_method: false) + expect(method_commits.map(&:sha)).to eq([commit_3.sha, commit_2.sha]) - expect(method_diffs.map(&:to_s)).to eq([ - "+ def bar; end\n", - "- def bar; end\n" - ]) end + it 'continues past lastest introduction of method if required even if method not defined in latest commit' do + repository = Repository.new(repository_path) + commit_1 = repository.commit(source(path: 'foo.rb', source: %{ + class Foo + def bar; end + end + })) + commit_2 = repository.commit(source(path: 'foo.rb', source: %{ + class Foo + end + })) + commit_3 = repository.commit(source(path: 'foo.rb', source: %{ + class Foo + def bar; end + end + })) + commit_4 = repository.commit(source(path: 'foo.rb', source: %{ + class Foo + end + })) + + method_commits, method_diffs = commits_and_diffs_for('Foo#bar', stop_at_latest_introduction_of_method: false) + + expect(method_commits.map(&:sha)).to eq([commit_4.sha, commit_3.sha, commit_2.sha]) + end + private - def commits_and_diffs_for(method_identifier) + def commits_and_diffs_for(method_identifier, options = {}) api = API.new(Repository.new(repository_path)) - commits_and_diffs = api.diffs(method_identifier) + commits_and_diffs = api.diffs(method_identifier, options) method_commits = commits_and_diffs.map(&:first) method_diffs = commits_and_diffs.map(&:last) [method_commits, method_diffs] end end \ No newline at end of file