Skip to content

Commit

Permalink
Upgrade subject.should -> expect(subject).to RSpec syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
blambeau committed May 18, 2024
1 parent 9eb9b7b commit 5344f1d
Show file tree
Hide file tree
Showing 49 changed files with 634 additions and 254 deletions.
16 changes: 12 additions & 4 deletions spec/factory/shared/a_comparison_factory_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
subject{ self.send(method, true, true) }

it_should_behave_like "a predicate AST node"
it{ should be_a(node_class) }
it{ should eql([method, tautology, tautology]) }
it {
expect(subject).to be_a(node_class)
}
it {
expect(subject).to eql([method, tautology, tautology])
}
end

context 'with a Hash operand (singleton)' do
Expand All @@ -18,7 +22,9 @@
}

it_should_behave_like "a predicate AST node"
it{ should eql(expected) }
it {
expect(subject).to eql(expected)
}
end

context 'with a Hash operand' do
Expand All @@ -30,7 +36,9 @@
}

it_should_behave_like "a predicate AST node"
it{ should eql(expected) }
it {
expect(subject).to eql(expected)
}
end

end
16 changes: 11 additions & 5 deletions spec/factory/shared/a_predicate_ast_node.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
require 'spec_helper'
shared_examples_for "a predicate AST node" do

it{ should be_a(Sexpr) }
it {
expect(subject).to be_a(Sexpr)
}

it{ should be_a(Predicate::Expr) }
it {
expect(subject).to be_a(Predicate::Expr)
}

specify{
(subject.tautology? == subject.is_a?(Predicate::Tautology)).should be(true)
got = (subject.tautology? == subject.is_a?(Predicate::Tautology))
expect(got).to be(true)
}

specify{
(subject.contradiction? == subject.is_a?(Predicate::Contradiction)).should be(true)
got = (subject.contradiction? == subject.is_a?(Predicate::Contradiction))
expect(got).to be(true)
}

specify{
subject.free_variables.should be_a(Array) unless subject.is_a?(Predicate::Native)
expect(subject.free_variables).to be_a(Array) unless subject.is_a?(Predicate::Native)
}

end
4 changes: 3 additions & 1 deletion spec/factory/test_${op_name}.rb.jeny
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Predicate

it_should_behave_like "a predicate AST node"

it{ should be_a(${OpName}) }
it {
expect(subject).to be_a(${OpName})
}
end
end
8 changes: 6 additions & 2 deletions spec/factory/test_and.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ class Predicate
subject{ self.and(true, true) }

it_should_behave_like "a predicate AST node"
it{ should be_a(And) }
it{ should eql([:and, tautology, tautology]) }
it {
expect(subject).to be_a(And)
}
it {
expect(subject).to eql([:and, tautology, tautology])
}

end
end
36 changes: 27 additions & 9 deletions spec/factory/test_comp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ class Predicate
context "when the hash is empty" do
let(:h){ {} }

it{ should eq(Factory.tautology) }
it {
expect(subject).to eq(Factory.tautology)
}
end

context "when the hash is a singelton" do
let(:h){ {:x => 12} }

it_should_behave_like "a predicate AST node"
it{ should be_a(Eq) }
it{ should eq([:eq, [:identifier, :x], [:literal, 12]]) }
it {
expect(subject).to be_a(Eq)
}
it {
expect(subject).to eq([:eq, [:identifier, :x], [:literal, 12]])
}
end

context "when the hash is not singleton" do
Expand All @@ -27,17 +33,25 @@ class Predicate
}

it_should_behave_like "a predicate AST node"
it{ should be_a(And) }
it{ should eq(expected) }
it {
expect(subject).to be_a(And)
}
it {
expect(subject).to eq(expected)
}
end

context "when the value is a Regexp" do
let(:rx){ /[a-z]+/ }
let(:h){ {:x => /[a-z]+/} }

it_should_behave_like "a predicate AST node"
it{ should be_a(Match) }
it{ should eq([:match, [:identifier, :x], [:literal, rx]]) }
it {
expect(subject).to be_a(Match)
}
it {
expect(subject).to eq([:match, [:identifier, :x], [:literal, rx]])
}
end

context "when the hash mixes value types" do
Expand All @@ -50,8 +64,12 @@ class Predicate
}

it_should_behave_like "a predicate AST node"
it{ should be_a(And) }
it{ should eq(expected) }
it {
expect(subject).to be_a(And)
}
it {
expect(subject).to eq(expected)
}
end

end
Expand Down
4 changes: 3 additions & 1 deletion spec/factory/test_contradiction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Predicate
subject{ contradiction }

it_should_behave_like "a predicate AST node"
it{ should be_a(Contradiction) }
it {
expect(subject).to be_a(Contradiction)
}
end
end
4 changes: 3 additions & 1 deletion spec/factory/test_empty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Predicate

it_should_behave_like "a predicate AST node"

it{ should be_a(Empty) }
it {
expect(subject).to be_a(Empty)
}
end
end
28 changes: 21 additions & 7 deletions spec/factory/test_factor_predicate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,57 @@ class Predicate
context "on Expr" do
let(:arg){ Grammar.sexpr([:literal, 12]) }

it{ should be(arg) }
it {
expect(subject).to be(arg)
}
end

context "on true" do
let(:arg){ true }

it{ should be_a(Tautology) }
it {
expect(subject).to be_a(Tautology)
}
end

context "on false" do
let(:arg){ false }

it{ should be_a(Contradiction) }
it {
expect(subject).to be_a(Contradiction)
}
end

context "on Symbol" do
let(:arg){ :name }

it{ should be_a(Identifier) }
it {
expect(subject).to be_a(Identifier)
}
end

context "on Proc" do
let(:arg){ lambda{} }

it{ should be_a(Native) }
it {
expect(subject).to be_a(Native)
}
end

context "on Array" do
let(:arg){ [:identifier, :name] }

it{ should be_a(Identifier) }
it {
expect(subject).to be_a(Identifier)
}
end

context "on 12" do
let(:arg){ 12 }

it{ should be_a(Literal) }
it {
expect(subject).to be_a(Literal)
}
end

end
Expand Down
28 changes: 21 additions & 7 deletions spec/factory/test_from_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ class Predicate
context "when the hash is empty" do
let(:h){ {} }

it{ should eq(Factory.tautology) }
it {
expect(subject).to eq(Factory.tautology)
}
end

context "when the hash is a singelton" do
let(:h){ {:x => 12} }

it_should_behave_like "a predicate AST node"
it{ should be_a(Eq) }
it{ should eq([:eq, [:identifier, :x], [:literal, 12]]) }
it {
expect(subject).to be_a(Eq)
}
it {
expect(subject).to eq([:eq, [:identifier, :x], [:literal, 12]])
}
end

context "when the hash is not a singleton" do
Expand All @@ -27,8 +33,12 @@ class Predicate
}

it_should_behave_like "a predicate AST node"
it{ should be_a(And) }
it{ should eq(expected) }
it {
expect(subject).to be_a(And)
}
it {
expect(subject).to eq(expected)
}
end

context "when the hash has array values" do
Expand All @@ -40,8 +50,12 @@ class Predicate
}

it_should_behave_like "a predicate AST node"
it{ should be_a(And) }
it{ should eq(expected) }
it {
expect(subject).to be_a(And)
}
it {
expect(subject).to eq(expected)
}
end

end
Expand Down
4 changes: 3 additions & 1 deletion spec/factory/test_has_size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Predicate

it_should_behave_like "a predicate AST node"

it{ should be_a(HasSize) }
it {
expect(subject).to be_a(HasSize)
}
end
end
8 changes: 6 additions & 2 deletions spec/factory/test_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ class Predicate
subject{ identifier(:name) }

it_should_behave_like "a predicate AST node"
it{ should be_a(Identifier) }
it{ should eql([:identifier, :name]) }
it {
expect(subject).to be_a(Identifier)
}
it {
expect(subject).to eql([:identifier, :name])
}

end
end
8 changes: 6 additions & 2 deletions spec/factory/test_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ class Predicate
subject{ literal(12) }

it_should_behave_like "a predicate AST node"
it{ should be_a(Literal) }
it{ should eql([:literal, 12]) }
it {
expect(subject).to be_a(Literal)
}
it {
expect(subject).to eql([:literal, 12])
}

end
end
16 changes: 12 additions & 4 deletions spec/factory/test_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ class Predicate

it_should_behave_like "a predicate AST node"

it{ should be_a(Match) }
it {
expect(subject).to be_a(Match)
}

it{ should eql([:match, [:identifier, :name], [:literal, "London"]]) }
it {
expect(subject).to eql([:match, [:identifier, :name], [:literal, "London"]])
}
end

context 'with options' do
subject{ match(:name, "London", case_sensitive: false) }

it_should_behave_like "a predicate AST node"

it{ should be_a(Match) }
it {
expect(subject).to be_a(Match)
}

it{ should eql([:match, [:identifier, :name], [:literal, "London"], {case_sensitive: false}]) }
it {
expect(subject).to eql([:match, [:identifier, :name], [:literal, "London"], {case_sensitive: false}])
}
end

end
Expand Down
8 changes: 6 additions & 2 deletions spec/factory/test_native.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ class Predicate

it_should_behave_like "a predicate AST node"

it{ should be_a(Native) }
it {
expect(subject).to be_a(Native)
}

it{ should eql([:native, proc]) }
it {
expect(subject).to eql([:native, proc])
}
end

end
Expand Down
Loading

0 comments on commit 5344f1d

Please sign in to comment.