Class: CommitMeat::Tester

Inherits:
Object
  • Object
show all
Defined in:
lib/commit-meat/tester.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Tester

Returns a new instance of Tester.



7
8
9
10
# File 'lib/commit-meat/tester.rb', line 7

def initialize(message)
  @message = message
  @failure_messages = []
end

Instance Attribute Details

#failure_messagesObject (readonly)

Returns the value of attribute failure_messages.



5
6
7
# File 'lib/commit-meat/tester.rb', line 5

def failure_messages
  @failure_messages
end

Instance Method Details

#check_if(bad_commit_test, failure_message) ⇒ Object



21
22
23
24
25
# File 'lib/commit-meat/tester.rb', line 21

def check_if(bad_commit_test, failure_message)
  if send(bad_commit_test)
    @failure_messages << failure_message
  end
end

#failed?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/commit-meat/tester.rb', line 12

def failed?
  @failure_messages.any?
end

#has_only_one_wordObject

tests



29
30
31
# File 'lib/commit-meat/tester.rb', line 29

def has_only_one_word
  @message.split.size == 1
end

#includes_bad_wordsObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/commit-meat/tester.rb', line 33

def includes_bad_words
  bad_words = YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'config/bad_words.yml'))
  bad_words_found = []

  bad_words.each do |word|
    bad_words_found << word if @message.include?(word)
  end

  bad_words_found.any?
end

#testObject



16
17
18
19
# File 'lib/commit-meat/tester.rb', line 16

def test
  check_if :has_only_one_word,  "Single word commit messages are not allowed."
  check_if :includes_bad_words, "Bad words are not allowed in commit messages."
end