Skip to content

Commit

Permalink
Convert specs to RSpec 2.14.8 syntax with Transpec
Browse files Browse the repository at this point in the history
This conversion is done by Transpec 2.3.1 with the following command:
    transpec

* 72 conversions
    from: obj.should
      to: expect(obj).to

* 33 conversions
    from: == expected
      to: eq(expected)

* 11 conversions
    from: obj.should_not
      to: expect(obj).not_to

* 7 conversions
    from: obj.should_receive(:message)
      to: expect(obj).to receive(:message)

* 1 conversion
    from: lambda { }.should
      to: expect { }.to

* 1 conversion
    from: lambda { }.should_not
      to: expect { }.not_to

For more details: https://github.com/yujinakayama/transpec#supported-conversions
  • Loading branch information
petergoldstein committed Jun 24, 2014
1 parent ede737c commit f7c4670
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 91 deletions.
112 changes: 56 additions & 56 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@
describe "configuration" do
it "should add an input_matrix by 'key'" do
BaseRecommender.input_matrix(:myinput)
BaseRecommender.input_matrices.keys.should == [:myinput]
expect(BaseRecommender.input_matrices.keys).to eq([:myinput])
end

it "should default the similarity_limit to 128" do
BaseRecommender.similarity_limit.should == 128
expect(BaseRecommender.similarity_limit).to eq(128)
end

it "should allow the similarity limit to be configured" do
BaseRecommender.limit_similarities_to(500)
BaseRecommender.similarity_limit.should == 500
expect(BaseRecommender.similarity_limit).to eq(500)
end

it "should allow the similarity limit to be removed" do
BaseRecommender.limit_similarities_to(nil)
BaseRecommender.similarity_limit.should == nil
expect(BaseRecommender.similarity_limit).to eq(nil)
end

it "should retrieve an input_matrix on a new instance" do
BaseRecommender.input_matrix(:myinput)
sm = BaseRecommender.new
lambda{ sm.myinput }.should_not raise_error
expect{ sm.myinput }.not_to raise_error
end

it "should retrieve an input_matrix on a new instance and correctly overload respond_to?" do
BaseRecommender.input_matrix(:myinput)
sm = BaseRecommender.new
sm.respond_to?(:process!).should be_true
sm.respond_to?(:myinput).should be_true
sm.respond_to?(:fnord).should be_false
expect(sm.respond_to?(:process!)).to be_true
expect(sm.respond_to?(:myinput)).to be_true
expect(sm.respond_to?(:fnord)).to be_false
end

it "should retrieve an input_matrix on a new instance and intialize the correct class" do
BaseRecommender.input_matrix(:myinput)
sm = BaseRecommender.new
sm.myinput.should be_a(Predictor::InputMatrix)
expect(sm.myinput).to be_a(Predictor::InputMatrix)
end
end

Expand Down Expand Up @@ -140,8 +140,8 @@
sm = BaseRecommender.new
sm.add_to_matrix(:anotherinput, 'a', "foo", "bar")
sm.add_to_matrix(:yetanotherinput, 'b', "fnord", "shmoo", "bar")
sm.all_items.should include('foo', 'bar', 'fnord', 'shmoo')
sm.all_items.length.should == 4
expect(sm.all_items).to include('foo', 'bar', 'fnord', 'shmoo')
expect(sm.all_items.length).to eq(4)
end

it "doesn't return items from other recommenders" do
Expand All @@ -164,24 +164,24 @@
it "calls add_to_set on the given matrix" do
BaseRecommender.input_matrix(:anotherinput)
sm = BaseRecommender.new
sm.anotherinput.should_receive(:add_to_set).with('a', 'foo', 'bar')
expect(sm.anotherinput).to receive(:add_to_set).with('a', 'foo', 'bar')
sm.add_to_matrix(:anotherinput, 'a', 'foo', 'bar')
end

it "adds the items to the all_items storage" do
BaseRecommender.input_matrix(:anotherinput)
sm = BaseRecommender.new
sm.add_to_matrix(:anotherinput, 'a', 'foo', 'bar')
sm.all_items.should include('foo', 'bar')
expect(sm.all_items).to include('foo', 'bar')
end
end

describe "add_to_matrix!" do
it "calls add_to_matrix and process_items! for the given items" do
BaseRecommender.input_matrix(:anotherinput)
sm = BaseRecommender.new
sm.should_receive(:add_to_matrix).with(:anotherinput, 'a', 'foo')
sm.should_receive(:process_items!).with('foo')
expect(sm).to receive(:add_to_matrix).with(:anotherinput, 'a', 'foo')
expect(sm).to receive(:process_items!).with('foo')
sm.add_to_matrix!(:anotherinput, 'a', 'foo')
end
end
Expand All @@ -196,8 +196,8 @@
sm.yetanotherinput.add_to_set('b', "fnord", "shmoo", "bar")
sm.finalinput.add_to_set('c', "nada")
sm.process!
sm.related_items("bar").should include("foo", "fnord", "shmoo")
sm.related_items("bar").length.should == 3
expect(sm.related_items("bar")).to include("foo", "fnord", "shmoo")
expect(sm.related_items("bar").length).to eq(3)
end
end

Expand All @@ -215,13 +215,13 @@
sm.tags.add_to_set('tag3', "shmoo", "nada")
sm.process!
predictions = sm.predictions_for('me', matrix_label: :users)
predictions.should == ["shmoo", "other", "nada"]
expect(predictions).to eq(["shmoo", "other", "nada"])
predictions = sm.predictions_for(item_set: ["foo", "bar", "fnord"])
predictions.should == ["shmoo", "other", "nada"]
expect(predictions).to eq(["shmoo", "other", "nada"])
predictions = sm.predictions_for('me', matrix_label: :users, offset: 1, limit: 1)
predictions.should == ["other"]
expect(predictions).to eq(["other"])
predictions = sm.predictions_for('me', matrix_label: :users, offset: 1)
predictions.should == ["other", "nada"]
expect(predictions).to eq(["other", "nada"])
end

it "accepts a :boost option" do
Expand Down Expand Up @@ -304,7 +304,7 @@
describe "similarities_for" do
it "should not throw exception for non existing items" do
sm = BaseRecommender.new
sm.similarities_for("not_existing_item").length.should == 0
expect(sm.similarities_for("not_existing_item").length).to eq(0)
end

it "correctly weighs and sums input matrices" do
Expand All @@ -322,10 +322,10 @@
sm.tags.add_to_set('tag2', "c1", "c4")

sm.process!
sm.similarities_for("c1", with_scores: true).should eq([["c4", 6.5], ["c2", 2.0]])
sm.similarities_for("c2", with_scores: true).should eq([["c3", 4.0], ["c1", 2.0], ["c4", 1.5]])
sm.similarities_for("c3", with_scores: true).should eq([["c2", 4.0], ["c4", 0.5]])
sm.similarities_for("c4", with_scores: true, exclusion_set: ["c3"]).should eq([["c1", 6.5], ["c2", 1.5]])
expect(sm.similarities_for("c1", with_scores: true)).to eq([["c4", 6.5], ["c2", 2.0]])
expect(sm.similarities_for("c2", with_scores: true)).to eq([["c3", 4.0], ["c1", 2.0], ["c4", 1.5]])
expect(sm.similarities_for("c3", with_scores: true)).to eq([["c2", 4.0], ["c4", 0.5]])
expect(sm.similarities_for("c4", with_scores: true, exclusion_set: ["c3"])).to eq([["c1", 6.5], ["c2", 1.5]])
end
end

Expand All @@ -337,9 +337,9 @@
sm.set1.add_to_set "item1", "foo", "bar"
sm.set1.add_to_set "item2", "nada", "bar"
sm.set2.add_to_set "item3", "bar", "other"
sm.sets_for("bar").length.should == 3
sm.sets_for("bar").should include("item1", "item2", "item3")
sm.sets_for("other").should == ["item3"]
expect(sm.sets_for("bar").length).to eq(3)
expect(sm.sets_for("bar")).to include("item1", "item2", "item3")
expect(sm.sets_for("other")).to eq(["item3"])
end
end

Expand All @@ -354,10 +354,10 @@
sm.mysecondinput.add_to_set 'set2', 'item2', 'item3'
sm.mythirdinput.add_to_set 'set3', 'item2', 'item3'
sm.mythirdinput.add_to_set 'set4', 'item1', 'item2', 'item3'
sm.similarities_for('item2').should be_empty
expect(sm.similarities_for('item2')).to be_empty
sm.process_items!('item2')
similarities = sm.similarities_for('item2', with_scores: true)
similarities.should include(["item3", 4.0], ["item1", 2.5])
expect(similarities).to include(["item3", 4.0], ["item1", 2.5])
end
end

Expand All @@ -372,11 +372,11 @@
sm.mysecondinput.add_to_set 'set2', 'item2', 'item3'
sm.mythirdinput.add_to_set 'set3', 'item2', 'item3'
sm.mythirdinput.add_to_set 'set4', 'item1', 'item2', 'item3'
sm.similarities_for('item2').should be_empty
expect(sm.similarities_for('item2')).to be_empty
sm.process_items!('item2')
similarities = sm.similarities_for('item2', with_scores: true)
similarities.should include(["item3", 4.0])
similarities.length.should == 1
expect(similarities).to include(["item3", 4.0])
expect(similarities.length).to eq(1)
end
end
end
Expand All @@ -388,8 +388,8 @@
sm = BaseRecommender.new
sm.anotherinput.add_to_set('a', "foo", "bar")
sm.yetanotherinput.add_to_set('b', "fnord", "shmoo")
sm.all_items.should include("foo", "bar", "fnord", "shmoo")
sm.should_receive(:process_items!).with(*sm.all_items)
expect(sm.all_items).to include("foo", "bar", "fnord", "shmoo")
expect(sm).to receive(:process_items!).with(*sm.all_items)
sm.process!
end
end
Expand All @@ -402,8 +402,8 @@
sm.anotherinput.add_to_set('a', "foo", "bar")
sm.yetanotherinput.add_to_set('b', "bar", "shmoo")
sm.process!
sm.similarities_for('bar').should include('foo', 'shmoo')
sm.anotherinput.should_receive(:delete_item).with('foo')
expect(sm.similarities_for('bar')).to include('foo', 'shmoo')
expect(sm.anotherinput).to receive(:delete_item).with('foo')
sm.delete_from_matrix!(:anotherinput, 'foo')
end

Expand All @@ -414,9 +414,9 @@
sm.anotherinput.add_to_set('a', "foo", "bar")
sm.yetanotherinput.add_to_set('b', "bar", "shmoo")
sm.process!
sm.similarities_for('bar').should include('foo', 'shmoo')
expect(sm.similarities_for('bar')).to include('foo', 'shmoo')
sm.delete_from_matrix!(:anotherinput, 'foo')
sm.similarities_for('bar').should == ['shmoo']
expect(sm.similarities_for('bar')).to eq(['shmoo'])
end
end

Expand All @@ -425,8 +425,8 @@
BaseRecommender.input_matrix(:myfirstinput)
BaseRecommender.input_matrix(:mysecondinput)
sm = BaseRecommender.new
sm.myfirstinput.should_receive(:delete_item).with("fnorditem")
sm.mysecondinput.should_receive(:delete_item).with("fnorditem")
expect(sm.myfirstinput).to receive(:delete_item).with("fnorditem")
expect(sm.mysecondinput).to receive(:delete_item).with("fnorditem")
sm.delete_item!("fnorditem")
end

Expand All @@ -435,9 +435,9 @@
sm = BaseRecommender.new
sm.anotherinput.add_to_set('a', "foo", "bar")
sm.process!
sm.all_items.should include('foo')
expect(sm.all_items).to include('foo')
sm.delete_item!('foo')
sm.all_items.should_not include('foo')
expect(sm.all_items).not_to include('foo')
end

it "should remove the item's similarities and also remove the item from related_items' similarities" do
Expand All @@ -447,11 +447,11 @@
sm.anotherinput.add_to_set('a', "foo", "bar")
sm.yetanotherinput.add_to_set('b', "bar", "shmoo")
sm.process!
sm.similarities_for('bar').should include('foo', 'shmoo')
sm.similarities_for('shmoo').should include('bar')
expect(sm.similarities_for('bar')).to include('foo', 'shmoo')
expect(sm.similarities_for('shmoo')).to include('bar')
sm.delete_item!('shmoo')
sm.similarities_for('bar').should_not include('shmoo')
sm.similarities_for('shmoo').should be_empty
expect(sm.similarities_for('bar')).not_to include('shmoo')
expect(sm.similarities_for('shmoo')).to be_empty
end
end

Expand All @@ -464,9 +464,9 @@
sm.set1.add_to_set "item2", "nada", "bar"
sm.set2.add_to_set "item3", "bar", "other"

Predictor.redis.keys(sm.redis_key('*')).should_not be_empty
expect(Predictor.redis.keys(sm.redis_key('*'))).not_to be_empty
sm.clean!
Predictor.redis.keys(sm.redis_key('*')).should be_empty
expect(Predictor.redis.keys(sm.redis_key('*'))).to be_empty
end
end

Expand All @@ -477,20 +477,20 @@
BaseRecommender.input_matrix(:myfirstinput)
sm = BaseRecommender.new
sm.myfirstinput.add_to_set *(['set1'] + 130.times.map{|i| "item#{i}"})
sm.similarities_for('item2').should be_empty
expect(sm.similarities_for('item2')).to be_empty
sm.process_items!('item2')
sm.similarities_for('item2').length.should == 129
expect(sm.similarities_for('item2').length).to eq(129)

redis = Predictor.redis
key = sm.redis_key(:similarities, 'item2')
redis.zcard(key).should == 129
redis.object(:encoding, key).should == 'skiplist' # Inefficient
expect(redis.zcard(key)).to eq(129)
expect(redis.object(:encoding, key)).to eq('skiplist') # Inefficient

BaseRecommender.reset_similarity_limit!
sm.ensure_similarity_limit_is_obeyed!

redis.zcard(key).should == 128
redis.object(:encoding, key).should == 'ziplist' # Efficient
expect(redis.zcard(key)).to eq(128)
expect(redis.object(:encoding, key)).to eq('ziplist') # Efficient
end
end
end
Loading

0 comments on commit f7c4670

Please sign in to comment.