Class: AhnnotateUpToDateMatcher
- Inherits:
-
Object
- Object
- AhnnotateUpToDateMatcher
- Defined in:
- lib/ahnnotate/rspec.rb
Overview
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
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
Instance Method Summary collapse
- #description ⇒ Object
- #diffable? ⇒ Boolean
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #matches?(_) ⇒ Boolean
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
12 13 14 |
# File 'lib/ahnnotate/rspec.rb', line 12 def actual @actual end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
13 14 15 |
# File 'lib/ahnnotate/rspec.rb', line 13 def expected @expected end |
Instance Method Details
#description ⇒ Object
41 42 43 |
# File 'lib/ahnnotate/rspec.rb', line 41 def description "be up to date (you may need to run `rails db:test:prepare`)" end |
#diffable? ⇒ Boolean
15 16 17 |
# File 'lib/ahnnotate/rspec.rb', line 15 def diffable? true end |
#failure_message ⇒ Object
45 46 47 |
# File 'lib/ahnnotate/rspec.rb', line 45 def "expected Ahnnotate to be up to date" end |
#failure_message_when_negated ⇒ Object
49 50 51 |
# File 'lib/ahnnotate/rspec.rb', line 49 def "expected Ahnnotate not to be up to date" end |
#matches?(_) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ahnnotate/rspec.rb', line 19 def matches?(_) = Ahnnotate::Options.new(fix: false) config = Ahnnotate::Config.load(root: Rails.root) main = Ahnnotate::Function::Main.new(Rails.root, , 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 |