Created
April 22, 2014 04:25
-
-
Save udzura/11165321 to your computer and use it in GitHub Desktop.
serverspecでMySQLの設定を検査する抹茶ー ref: http://qiita.com/udzura/items/7284742edf0f0f1164e3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec::Matchers.define :have_mysql_entry do |entry| | |
match do |subject| | |
if subject.class.name == 'Serverspec::Type::File' | |
@content = subject.content | |
if @value | |
!! @content.lines.find {|line| line =~ /^\s*#{entry}\s*=\s*#{@value}\s*$/ } | |
else | |
!! @content.lines.find {|line| line =~ /^\s*#{entry}\s?=/ } | |
end | |
else | |
raise "have_mysql_entry matcher should target to file resource" | |
end | |
end | |
chain :with_value do |value| | |
@value = value | |
end | |
failure_message_for_should do |actual| | |
if @value | |
m = "expected #{actual.to_s} to have mysql entry #{entry.inspect} with value #{@value.inspect}" | |
if match = @content.match(/^(\s*#{entry}\s?=.*)/) | |
m << "\n entry #{match[1].inspect} exists, but value not matched." | |
end | |
else | |
m = "expected #{actual.to_s} to have mysql entry #{entry.inspect}" | |
end | |
m | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe file('/etc/my.cnf') do | |
it { should be_file } | |
it { should have_mysql_entry('default-character-set').with_value('utf8') } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment