spec/app/models/metasploit/model/search/query_spec.rb in metasploit-model-0.30.2-java vs spec/app/models/metasploit/model/search/query_spec.rb in metasploit-model-1.0.0.pre.rails.pre.4.0

- old
+ new

@@ -1,8 +1,10 @@ -RSpec.describe Metasploit::Model::Search::Query, type: :model do +require 'spec_helper' + +describe Metasploit::Model::Search::Query do context 'validations' do - it { is_expected.to validate_presence_of :klass } + it { should validate_presence_of :klass } context 'operations' do let(:errors) do query.errors[:operations] end @@ -41,25 +43,25 @@ let(:formatted) do '' end it 'should have no operations' do - expect(query.operations.length).to eq(0) + query.operations.length.should == 0 end it 'should record error on operations' do - expect(errors).to include(error) + errors.should include(error) end end context 'without empty' do let(:formatted) do 'formatted_operator:formatted_value' end it 'should not record error on operations' do - expect(errors).not_to include(error) + errors.should_not include(error) end end end context 'valid' do @@ -71,30 +73,30 @@ described_class.new end before(:each) do operation = double('Invalid Operation', :valid? => valid) - allow(query).to receive(:operations).and_return([operation]) + query.stub(:operations).and_return([operation]) end context 'with invalid operation' do let(:valid) do false end it 'should record error on operations' do - expect(errors).not_to include(error) + errors.should_not include(error) end end context 'without invalid operation' do let(:valid) do true end it 'should not record error on options' do - expect(errors).not_to include(error) + errors.should_not include(error) end end end end end @@ -113,15 +115,15 @@ it 'should parse the correct number of formatted_operations' do expect(formatted_operations.length).to eq(2) end it 'should include operation with space in value' do - expect(formatted_operations).to include('formatted_operator1:formatted value:1') + formatted_operations.should include('formatted_operator1:formatted value:1') end it 'should include operation without space in value' do - expect(formatted_operations).to include('formatted_operator2:formatted_value2') + formatted_operations.should include('formatted_operator2:formatted_value2') end end context 'with unquoted value' do let(:expected_formatted_operations) do @@ -168,11 +170,11 @@ formatted_operations: expected_formatted_operations ) end it 'should equal attribute passed to #initialize' do - expect(formatted_operations).to eq(expected_formatted_operations) + formatted_operations.should == expected_formatted_operations end end context 'without :formatted_operations attribute' do let(:formatted) do @@ -204,11 +206,11 @@ # include after stubbing const so that search_i18n_scope can use Class#name klass.send(:include, Metasploit::Model::Search) end it 'should parse #formatted with formatted_operations' do - expect(described_class).to receive(:formatted_operations).with(formatted).and_return([]) + described_class.should_receive(:formatted_operations).with(formatted).and_return([]) formatted_operations end end end @@ -228,11 +230,11 @@ operations: expected_operations ) end it 'should use attribute passed to #initialize' do - expect(operations).to eq(expected_operations) + operations.should == expected_operations end end context 'without :operations attribute' do let(:attribute) do @@ -268,11 +270,11 @@ # include after stubbing const so that search_i18n_scope can use Class#name klass.send(:include, Metasploit::Model::Search) end it 'should call #formatted_operations' do - expect(query).to receive(:formatted_operations).and_return([]) + query.should_receive(:formatted_operations).and_return([]) operations end context 'with known operator' do @@ -295,114 +297,114 @@ context 'with boolean operator' do let(:type) do :boolean end - it { is_expected.to be_a Metasploit::Model::Search::Operation::Boolean } + it { should be_a Metasploit::Model::Search::Operation::Boolean } context "with 'true'" do let(:formatted_value) do 'true' end - it { is_expected.to be_valid } + it { should be_valid } end context "with 'false'" do let(:formatted_value) do 'false' end - it { is_expected.to be_valid } + it { should be_valid } end context "without 'false' or 'true'" do let(:formatted_value) do 'no' end - it { is_expected.to_not be_valid } + it { should_not be_valid } end end context 'with date operator' do let(:type) do :date end - it { is_expected.to be_a Metasploit::Model::Search::Operation::Date } + it { should be_a Metasploit::Model::Search::Operation::Date } context 'with date' do let(:formatted_value) do Date.today.to_s end - it { is_expected.to be_valid } + it { should be_valid } end context 'without date' do let(:formatted_value) do 'yesterday' end - it { is_expected.to_not be_valid } + it { should_not be_valid } end end context 'with integer operator' do let(:type) do :integer end - it { is_expected.to be_a Metasploit::Model::Search::Operation::Integer } + it { should be_a Metasploit::Model::Search::Operation::Integer } context 'with integer' do let(:formatted_value) do '100' end - it { is_expected.to be_valid } + it { should be_valid } end context 'with float' do let(:formatted_value) do '100.5' end - it { is_expected.to be_invalid } + it { should be_invalid } end context 'with integer embedded in text' do let(:formatted_value) do 'a2c' end - it { is_expected.to be_invalid } + it { should be_invalid } end end context 'with string operator' do let(:type) do :string end - it { is_expected.to be_a Metasploit::Model::Search::Operation::String } + it { should be_a Metasploit::Model::Search::Operation::String } context 'with value' do let(:formatted_value) do 'formatted_value' end - it { is_expected.to be_valid } + it { should be_valid } end context 'without value' do let(:formatted_value) do '' end - it { is_expected.to_not be_valid } + it { should_not be_valid } end end end context 'without known operator' do @@ -416,13 +418,13 @@ let(:formatted_value) do 'unknown_value' end - it { is_expected.to be_a Metasploit::Model::Search::Operation::Base } + it { should be_a Metasploit::Model::Search::Operation::Base } - it { is_expected.to be_invalid } + it { should be_invalid } end end end context '#operations_by_operator' do @@ -464,11 +466,11 @@ formatted_operators.join(' ') end it 'should have correct number of groups' do - expect(operations_by_operator.length).to eq(@operators.length) + operations_by_operator.length.should == @operators.length end it 'should have correct value for each operator' do @operators.each_with_index do |operator, i| expected_formatted_values = 2.times.collect { |j| @@ -485,11 +487,11 @@ context 'query' do subject do query end - it { is_expected.to be_valid } + it { should be_valid } end end context 'without valid' do let(:formatted) do @@ -499,11 +501,11 @@ context 'query' do subject do query end - it { is_expected.to_not be_valid } + it { should_not be_valid } end end end context '#parse_operator' do @@ -538,31 +540,31 @@ attribute.to_s end context 'with String' do it 'should find operator' do - expect(parse_operator).to eq(@operator) + parse_operator.should == @operator end end context 'with Symbol' do let(:formatted_operator) do attribute end it 'should find operator' do - expect(parse_operator).to eq(@operator) + parse_operator.should == @operator end end end context 'without operator name' do let(:formatted_operator) do 'unknown_operator' end - it { is_expected.to be_a Metasploit::Model::Search::Operator::Null } + it { should be_a Metasploit::Model::Search::Operator::Null } end end context '#tree' do subject(:tree) do @@ -595,30 +597,30 @@ context 'root' do subject(:root) do tree end - it { is_expected.to be_a Metasploit::Model::Search::Group::Intersection } + it { should be_a Metasploit::Model::Search::Group::Intersection } context 'children' do subject(:children) do root.children end it 'should be an Array<Metasploit::Model::Search::Group::Union>' do children.each do |child| - expect(child).to be_a Metasploit::Model::Search::Group::Union + child.should be_a Metasploit::Model::Search::Group::Union end end it 'should have same operator for each child of a union' do children.each do |child| - operator_set = child.children.inject(Set.new) { |block_operator_set, operation| - block_operator_set.add operation.operator + operator_set = child.children.inject(Set.new) { |operator_set, operation| + operator_set.add operation.operator } - expect(operator_set.length).to eq(1) + operator_set.length.should == 1 end end context 'grandchildren' do let(:grandchildren) do @@ -631,11 +633,11 @@ grandchildren end it 'should be Array<Metasploit::Model::Search::Operation::Base>' do grandchildren.each do |grandchild| - expect(grandchild).to be_a Metasploit::Model::Search::Operation::Base + grandchild.should be_a Metasploit::Model::Search::Operation::Base end end end end end @@ -697,33 +699,33 @@ "#{operator.name}:value" } end it 'should return a new query' do - expect(without_operator).not_to be query + without_operator.should_not be query end it 'should not have operations on the removed operator' do - expect(without_operator.operations_by_operator[filtered_operator]).to be_blank + without_operator.operations_by_operator[filtered_operator].should be_blank end it 'should have same #klass as this query' do - expect(without_operator.klass).to eq(query.klass) + without_operator.klass.should == query.klass end context 'with no other operators' do let(:formatted_operations) do [ "#{filtered_operator.name}:value" ] end - it { is_expected.to_not be_valid } + it { should_not be_valid } end context 'with other operators' do - it { is_expected.to be_valid } + it { should be_valid } end end context 'without operator' do let(:formatted_operations) do @@ -731,10 +733,10 @@ "#{operator.name}:value" } end it 'should return this query' do - expect(without_operator).to be query + without_operator.should be query end end end end \ No newline at end of file