Class: RSpec::Snapshot::Matchers::MatchSnapShot
- Inherits:
-
Object
- Object
- RSpec::Snapshot::Matchers::MatchSnapShot
- Defined in:
- lib/rspec/snapshot/matchers/match_snapshot.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(metadata, snapshot_name) ⇒ MatchSnapShot
constructor
A new instance of MatchSnapShot.
- #matches?(actual) ⇒ Boolean
- #snapshot_dir ⇒ Object
Constructor Details
#initialize(metadata, snapshot_name) ⇒ MatchSnapShot
Returns a new instance of MatchSnapShot.
7 8 9 10 |
# File 'lib/rspec/snapshot/matchers/match_snapshot.rb', line 7 def initialize(, snapshot_name) @metadata = @snapshot_name = snapshot_name end |
Instance Method Details
#failure_message ⇒ Object
32 33 34 |
# File 'lib/rspec/snapshot/matchers/match_snapshot.rb', line 32 def "\nexpected: #{@expect}\n got: #{@actual}\n" end |
#matches?(actual) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rspec/snapshot/matchers/match_snapshot.rb', line 12 def matches?(actual) @actual = actual filename = "#{@snapshot_name}.snap" snap_path = File.join(snapshot_dir, filename) FileUtils.mkdir_p(File.dirname(snap_path)) unless Dir.exist?(File.dirname(snap_path)) if File.exist?(snap_path) file = File.new(snap_path) @expect = file.read file.close @actual == @expect else RSpec.configuration.reporter. "Generate #{snap_path}" file = File.new(snap_path, "w+") file.write(@actual) file.close true end end |