spec/app/models/metasploit/model/search/query_spec.rb in metasploit-model-0.30.0-java vs spec/app/models/metasploit/model/search/query_spec.rb in metasploit-model-0.30.1.pre.rspec.pre.3.pre.1

- old
+ new

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