summaryrefslogtreecommitdiff
path: root/spec/unit/search
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2014-10-29 15:14:22 -0700
committerClaire McQuin <claire@getchef.com>2014-10-29 15:59:04 -0700
commit5fed7a65a2f024d964ecf2de1bcf2911cf8a600c (patch)
tree14cc6968e4fe4fd2485c0211088b25c645a80a4b /spec/unit/search
parentb92c309b0f1aa0837f76ab89d6c81c36076ceca9 (diff)
downloadchef-5fed7a65a2f024d964ecf2de1bcf2911cf8a600c.tar.gz
Update to RSpec 3.
Diffstat (limited to 'spec/unit/search')
-rw-r--r--spec/unit/search/query_spec.rb60
1 files changed, 30 insertions, 30 deletions
diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb
index c7388a6234..d4ff9e4367 100644
--- a/spec/unit/search/query_spec.rb
+++ b/spec/unit/search/query_spec.rb
@@ -68,8 +68,8 @@ describe Chef::Search::Query do
end
before(:each) do
- Chef::REST.stub(:new).and_return(rest)
- rest.stub(:get_rest).and_return(response)
+ allow(Chef::REST).to receive(:new).and_return(rest)
+ allow(rest).to receive(:get_rest).and_return(response)
end
describe "search" do
@@ -133,57 +133,57 @@ describe Chef::Search::Query do
} }
it "should accept a type as the first argument" do
- lambda { query.search("node") }.should_not raise_error
- lambda { query.search(:node) }.should_not raise_error
- lambda { query.search(Hash.new) }.should raise_error(Chef::Exceptions::InvalidSearchQuery, /(Hash)/)
+ expect { query.search("node") }.not_to raise_error
+ expect { query.search(:node) }.not_to raise_error
+ expect { query.search(Hash.new) }.to raise_error(Chef::Exceptions::InvalidSearchQuery, /(Hash)/)
end
it "should query for every object of a type by default" do
- rest.should_receive(:get_rest).with("search/node?q=*:*&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=1000").and_return(response)
+ expect(rest).to receive(:get_rest).with("search/node?q=*:*&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=1000").and_return(response)
query.search(:node)
end
it "should allow a custom query" do
- rest.should_receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=1000").and_return(response)
+ expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=1000").and_return(response)
query.search(:node, "platform:rhel")
end
it "should let you set a sort order" do
- rest.should_receive(:get_rest).with("search/node?q=platform:rhel&sort=id%20desc&start=0&rows=1000").and_return(response)
+ expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=id%20desc&start=0&rows=1000").and_return(response)
query.search(:node, "platform:rhel", "id desc")
end
it "should let you set a starting object" do
- rest.should_receive(:get_rest).with("search/node?q=platform:rhel&sort=id%20desc&start=2&rows=1000").and_return(response)
+ expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=id%20desc&start=2&rows=1000").and_return(response)
query.search(:node, "platform:rhel", "id desc", 2)
end
it "should let you set how many rows to return" do
- rest.should_receive(:get_rest).with("search/node?q=platform:rhel&sort=id%20desc&start=2&rows=40").and_return(response)
+ expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=id%20desc&start=2&rows=40").and_return(response)
query.search(:node, "platform:rhel", "id desc", 2, 40)
end
it "should throw an exception if you pass to many options" do
- lambda { query.search(:node, "platform:rhel", "id desc", 2, 40, "wrong") }
- .should raise_error(Chef::Exceptions::InvalidSearchQuery, "Too many arguments! (4 for <= 3)")
+ expect { query.search(:node, "platform:rhel", "id desc", 2, 40, "wrong") }
+ .to raise_error(Chef::Exceptions::InvalidSearchQuery, "Too many arguments! (4 for <= 3)")
end
it "should return the raw rows, start, and total if no block is passed" do
rows, start, total = query.search(:node)
- rows.should equal(response["rows"])
- start.should equal(response["start"])
- total.should equal(response["total"])
+ expect(rows).to equal(response["rows"])
+ expect(start).to equal(response["start"])
+ expect(total).to equal(response["total"])
end
it "should call a block for each object in the response" do
@call_me = double("blocky")
- response["rows"].each { |r| @call_me.should_receive(:do).with(r) }
+ response["rows"].each { |r| expect(@call_me).to receive(:do).with(r) }
query.search(:node) { |r| @call_me.do(r) }
end
it "should page through the responses" do
@call_me = double("blocky")
- response["rows"].each { |r| @call_me.should_receive(:do).with(r) }
+ response["rows"].each { |r| expect(@call_me).to receive(:do).with(r) }
query.search(:node, "*:*", nil, 0, 1) { |r| @call_me.do(r) }
end
@@ -192,17 +192,17 @@ describe Chef::Search::Query do
let(:filter_key) { :filter_result }
before(:each) do
- rest.should_receive(:post_rest).with(query_string, args[filter_key]).and_return(response)
+ expect(rest).to receive(:post_rest).with(query_string, args[filter_key]).and_return(response)
end
it "should return start" do
start = query.search(:node, "platform:rhel", args)[1]
- start.should == response['start']
+ expect(start).to eq(response['start'])
end
it "should return total" do
total = query.search(:node, "platform:rhel", args)[2]
- total.should == response['total']
+ expect(total).to eq(response['total'])
end
it "should return rows with the filter applied" do
@@ -211,13 +211,13 @@ describe Chef::Search::Query do
results.each_with_index do |result, idx|
expected = response["rows"][idx]
- result.should have_key("url")
- result["url"].should == expected["url"]
+ expect(result).to have_key("url")
+ expect(result["url"]).to eq(expected["url"])
- result.should have_key("data")
+ expect(result).to have_key("data")
filter_hash.keys.each do |filter_key|
- result["data"].should have_key(filter_key)
- result["data"][filter_key].should == expected["data"][filter_key]
+ expect(result["data"]).to have_key(filter_key)
+ expect(result["data"][filter_key]).to eq(expected["data"][filter_key])
end
end
end
@@ -232,21 +232,21 @@ describe Chef::Search::Query do
it "should emit a deprecation warning" do
# partial_search calls search, so we'll stub search to return empty
- query.stub(:search).and_return( [ [], 0, 0 ] )
- Chef::Log.should_receive(:warn).with("DEPRECATED: The 'partial_search' api is deprecated, please use the search api with 'filter_result'")
+ allow(query).to receive(:search).and_return( [ [], 0, 0 ] )
+ expect(Chef::Log).to receive(:warn).with("DEPRECATED: The 'partial_search' api is deprecated, please use the search api with 'filter_result'")
query.partial_search(:node, "platform:rhel", args)
end
it "should return an array of filtered hashes" do
- rest.should_receive(:post_rest).with(query_string, args[filter_key]).and_return(response)
+ expect(rest).to receive(:post_rest).with(query_string, args[filter_key]).and_return(response)
results = query.partial_search(:node, "platform:rhel", args)
results.each_with_index do |result, idx|
expected = response["rows"][idx]
filter_hash.keys.each do |filter_key|
- result.should have_key(filter_key)
- result[filter_key].should == expected["data"][filter_key]
+ expect(result).to have_key(filter_key)
+ expect(result[filter_key]).to eq(expected["data"][filter_key])
end
end
end