spec/mem_spec.rb in mem-0.1.5 vs spec/mem_spec.rb in mem-0.2.0
- old
+ new
@@ -1,14 +1,20 @@
-require "spec_helper"
+# frozen_string_literal: true
-describe Mem do
- describe "#memoize" do
+require 'spec_helper'
+
+RSpec.describe Mem do
+ describe '#memoize' do
+ before do
+ allow(object).to receive(:b).and_call_original
+ end
+
let(:object) do
klass.new
end
- context "with normal method name" do
+ context 'with normal method name' do
let(:klass) do
Class.new do
include Mem
def a(value, &block)
@@ -19,30 +25,30 @@
def b(value)
[value, yield]
end
def c
- "c"
+ 'c'
end
memoize :c
end
end
- it "memoizes the method call" do
- expect(object).to receive(:b).once.and_call_original
+ it 'memoizes the method call' do
expect(object.a(1) { 2 }).to eq [1, 2]
expect(object.a(3) { 4 }).to eq [1, 2]
+ expect(object).to have_received(:b).once
end
- it "defines setter" do
- expect(object.c).to eq "c"
- object.c = "d"
- expect(object.c).to eq "d"
+ it 'defines setter' do
+ expect(object.c).to eq 'c'
+ object.c = 'd'
+ expect(object.c).to eq 'd'
end
end
- context "with abnormal method name" do
+ context 'with abnormal method name' do
let(:klass) do
Class.new do
include Mem
def a!(value, &block)
@@ -54,38 +60,35 @@
[value, yield]
end
end
end
- it "memoizes the method call" do
- expect(object).to receive(:b).once.and_call_original
+ it 'memoizes the method call' do
expect(object.a!(1) { 2 }).to eq [1, 2]
expect(object.a!(3) { 4 }).to eq [1, 2]
- object.should have_memoized(:a!)
- object.memoized(:a!).should == [1, 2]
- object.memoized_table.should == { a!: [1, 2] }
+ expect(object).to have_received(:b).once
+ expect(object).to have_memoized(:a!)
+ expect(object.memoized(:a!)).to eq [1, 2]
+ expect(object.memoized_table).to eq({ a!: [1, 2] })
end
end
- context "with non-public method name" do
+ context 'with non-public method name' do
let(:klass) do
Class.new do
include Mem
- def a
- end
+ def a; end
memoize :a
protected
- def b
- end
+ def b; end
memoize :b
private
- def c
- end
+ def c; end
memoize :c
end
end
it 'keeps method visibilities' do