# frozen_string_literal: true
require File.expand_path('../../spec_helper', __FILE__)
module Danger
describe Danger::DangerWCC do
before do
@dangerfile = testing_dangerfile
@my_plugin = @dangerfile.wcc
@git = @dangerfile.git
@github = @dangerfile.github
allow(@github).to receive(:html_link) do |text|
"#{text}"
end
end
describe 'todos' do
it 'Warns when TODO added' do
allow(@git).to receive(:diff)
.and_return([load_diff('spec/fixtures/todo.rb', 'todo_no_link')])
# act
@my_plugin.todos
expect(@dangerfile.violation_report[:warnings])
.to eq([Violation.new('TODO added in '\
'spec/fixtures/todo.rb'\
' - is there a card associated with that?',
false,
'spec/fixtures/todo.rb',
9)])
end
it 'Does not warn when TODO removed' do
allow(@git).to receive(:diff)
.and_return([load_diff('spec/fixtures/todo.rb', 'todo_removed')])
# act
@my_plugin.todos
expect(@dangerfile.violation_report[:warnings])
.to eq([])
end
it 'Does not warn when no TODO in diff' do
allow(@git).to receive(:diff)
.and_return([load_diff('spec/fixtures/todo.rb', 'no_todo')])
# act
@my_plugin.todos
expect(@dangerfile.violation_report[:warnings])
.to eq([])
end
it 'Sends message when todo has link' do
allow(@git).to receive(:diff)
.and_return(
[load_diff('spec/fixtures/todo.rb', 'todo_link_same_line')]
)
# act
@my_plugin.todos
expect(@dangerfile.violation_report[:messages])
.to eq([Violation.new('TODO added in '\
'spec/fixtures/todo.rb '\
'referencing [https://zube.io/watermark/asdf1234]'\
'(https://zube.io/watermark/asdf1234)',
false,
'spec/fixtures/todo.rb',
13)])
end
it 'Sends message when todo below link' do
allow(@git).to receive(:diff)
.and_return(
[load_diff('spec/fixtures/todo.rb', 'todo_link_next_line')]
)
# act
@my_plugin.todos
expect(@dangerfile.violation_report[:messages])
.to eq([Violation.new('TODO added in '\
'spec/fixtures/todo.rb '\
'referencing [https://www.github.com/watermarkchurch/asdf/1234]'\
'(https://www.github.com/watermarkchurch/asdf/1234)',
false,
'spec/fixtures/todo.rb',
18)])
end
end
end
end