Sha256: ef9b29947fd38fd15a50f0af92b3d4def6908b14b5b81e7c3ecbf7bdc75a5faf
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
require "ahnnotate" # This RSpec matcher only works for Rails. Here's a quick usage example: # # require "rails_helper" # require "ahnnotate/rspec" # # RSpec.describe Ahnnotate do # it { is_expected.to be_up_to_date } # end class AhnnotateUpToDateMatcher attr_reader :actual attr_reader :expected def diffable? true end def matches?(_) options = Ahnnotate::Options.new(fix: false) config = Ahnnotate::Config.load(root: Rails.root) main = Ahnnotate::Function::Main.new(Rails.root, options, config) main.call writes = main.vfs.instance_variable_get(:@driver).changes format = proc do |vfs_hash| vfs_hash .map { |path, contents| "~~~ #{path} ~~~\n#{contents}" } .join("\n") end expected = writes.map { |path, _content| [path, File.read(path)] }.to_h @expected = format.call(expected) @actual = format.call(writes) @actual == @expected end def description "be up to date (you may need to run `rails db:test:prepare`)" end def failure_message "expected Ahnnotate to be up to date" end def failure_message_when_negated "expected Ahnnotate not to be up to date" end end module AhnnotateBeUpToDate def be_up_to_date AhnnotateUpToDateMatcher.new end end RSpec.configure do |c| c.include AhnnotateBeUpToDate end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ahnnotate-0.5.1 | lib/ahnnotate/rspec.rb |
ahnnotate-0.5.0 | lib/ahnnotate/rspec.rb |