-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/tests-coverage'
- Loading branch information
Showing
9 changed files
with
460 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 77 additions & 3 deletions
80
spec/app/helpers/washout_builder_complex_type_helper_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,86 @@ | ||
require 'spec_helper' | ||
|
||
describe WashoutBuilderComplexTypeHelper do | ||
describe WashoutBuilderComplexTypeHelper, :type => :helper do | ||
|
||
describe '#create_element_type_html' do | ||
context '#create_element_type_html' do | ||
let (:pre) { [] } | ||
let(:element_name) {"custom_name"} | ||
let(:element) {mock} | ||
|
||
before(:each) do | ||
element.stubs(:type).returns("text") | ||
element.stubs(:type=).with("string") | ||
element.stubs(:name).returns(element_name) | ||
end | ||
|
||
def expect_included_type_result(pre, element) | ||
WashoutBuilder::Type::BASIC_TYPES.expects(:include?).with(element.type).returns(true) | ||
result =helper.create_element_type_html(pre, element) | ||
result.should eq(["<span class='blue'>#{element.type}</span> <span class='bold'>#{element.name}</span>"]) | ||
end | ||
|
||
def expect_excluded_type_result(pre, element) | ||
WashoutBuilder::Type::BASIC_TYPES.expects(:include?).with(element.type).returns(false) | ||
helper.expects(:create_complex_element_type_html).with(pre, element) | ||
helper.create_element_type_html(pre, element) | ||
end | ||
|
||
|
||
it "returns the element of type text" do | ||
element.expects(:type=).with("string") | ||
expect_included_type_result(pre, element) | ||
end | ||
|
||
it "returns the element of type text" do | ||
expect_excluded_type_result(pre, element) | ||
end | ||
|
||
it "returns the element of type integer" do | ||
element.stubs(:type).returns("int") | ||
element.expects(:type=).with("integer") | ||
expect_included_type_result(pre, element) | ||
end | ||
|
||
it "returns the element of type integer" do | ||
element.stubs(:type).returns("int") | ||
element.expects(:type=).with("integer") | ||
expect_excluded_type_result(pre, element) | ||
end | ||
|
||
|
||
end | ||
|
||
|
||
context "create_complex_element_type_html" do | ||
let (:pre) { [] } | ||
let(:element_name) {"custom_name"} | ||
let(:complex_class) {"SomeClass"} | ||
let(:element) {mock} | ||
|
||
before(:each) do | ||
element.stubs(:get_complex_class_name).returns(complex_class) | ||
element.stubs(:multiplied).returns(false) | ||
element.stubs(:name).returns(element_name) | ||
end | ||
|
||
it "returna simple type element description" do | ||
result = helper.create_complex_element_type_html(pre, element) | ||
result.should eq(["<a href='##{complex_class}'><span class='lightBlue'>#{complex_class}</span></a> <span class='bold'>#{element.name}</span>"]) | ||
end | ||
|
||
it "returns an array type element description" do | ||
element.stubs(:multiplied).returns(true) | ||
result = helper.create_complex_element_type_html(pre, element) | ||
result.should eq(["<a href='##{complex_class}'><span class='lightBlue'>Array of #{complex_class}</span></a> <span class='bold'>#{element.name}</span>"]) | ||
end | ||
|
||
it "returns empty if no complex class" do | ||
element.stubs(:get_complex_class_name).returns(nil) | ||
result = helper.create_complex_element_type_html(pre, element) | ||
result.should eq(nil) | ||
end | ||
|
||
end | ||
|
||
|
||
end | ||
end |
139 changes: 139 additions & 0 deletions
139
spec/app/helpers/washout_builder_fault_type_helper_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
require "spec_helper" | ||
|
||
describe WashoutBuilderFaultTypeHelper, :type => :helper do | ||
|
||
context " create_fault_model_complex_element_type" do | ||
let(:pre) { [] } | ||
let(:attr_primitive){ "string"} | ||
let(:attribute) {"custom_attribute"} | ||
|
||
def check_result(array) | ||
attribute_primitive = array == true ? "Array of #{attr_primitive}" : "#{attr_primitive}" | ||
result = helper. create_fault_model_complex_element_type(pre, attr_primitive, attribute, array) | ||
result.should eq(["<a href='##{attr_primitive}'><span class='lightBlue'> #{attribute_primitive}</span></a> <span class='bold'>#{attribute}</span>"]) | ||
end | ||
|
||
it "creates an array element " do | ||
check_result(true) | ||
end | ||
it "creates an simple element " do | ||
check_result(false) | ||
end | ||
end | ||
|
||
context "member_type_is_basic?" do | ||
|
||
it "returns a basic type" do | ||
attr_details = {:member_type => "STRING"} | ||
WashoutBuilder::Type::BASIC_TYPES.expects(:include?).with(attr_details[:member_type].to_s.downcase).returns(true) | ||
result = helper.member_type_is_basic?(attr_details) | ||
result.should eq(attr_details[:member_type].to_s.downcase) | ||
end | ||
|
||
it "returns a non-basic type" do | ||
attr_details = {:member_type => "STRING" } | ||
WashoutBuilder::Type::BASIC_TYPES.expects(:include?).with(attr_details[:member_type].to_s.downcase).returns(false) | ||
result = helper.member_type_is_basic?(attr_details) | ||
result.should eq(attr_details[:member_type]) | ||
end | ||
|
||
end | ||
|
||
context "primitive_type_is_basic?" do | ||
|
||
it "returns true" do | ||
attr_details = {:primitive => "STRING"} | ||
WashoutBuilder::Type::BASIC_TYPES.expects(:include?).with(attr_details[:primitive].to_s.downcase).returns(true) | ||
helper.primitive_type_is_basic?(attr_details).should eq(true) | ||
end | ||
|
||
it "returns false" do | ||
attr_details = {:primitive => "STRING"} | ||
WashoutBuilder::Type::BASIC_TYPES.expects(:include?).with(attr_details[:primitive].to_s.downcase).returns(false) | ||
helper.primitive_type_is_basic?(attr_details).should eq(false) | ||
end | ||
|
||
end | ||
|
||
context "get_primitive_type_string" do | ||
|
||
["NILCLASS", "nilclass"].each do |primitive| | ||
it "returns string in case of nilclass" do | ||
attr_details = {:primitive => primitive} | ||
helper.get_primitive_type_string(attr_details).should eq("string") | ||
end | ||
end | ||
|
||
["BLA", "bla"].each do |primitive| | ||
it "returns the primitive if not niclass" do | ||
attr_details = {:primitive => primitive} | ||
helper.get_primitive_type_string(attr_details).should eq(primitive.to_s.downcase) | ||
end | ||
end | ||
|
||
end | ||
|
||
context "get_member_type_string" do | ||
|
||
["Array", "array"].each do |primitive| | ||
it "checks the member type to be basic if primitive type array" do | ||
attr_details = {:primitive => primitive} | ||
helper.expects(:member_type_is_basic?).with(attr_details).returns(true) | ||
helper.get_member_type_string(attr_details).should eq(true) | ||
end | ||
end | ||
|
||
|
||
["BLA", "Bla", "bla"].each do |primitive| | ||
it "returns the primitive type as it is if not array" do | ||
attr_details = {:primitive => primitive} | ||
helper.get_member_type_string(attr_details).should eq(primitive) | ||
end | ||
end | ||
|
||
end | ||
|
||
context "create_html_fault_model_element_type" do | ||
let(:pre) {[]} | ||
let(:attribute) {"some_attribute"} | ||
|
||
before(:each) do | ||
helper.stubs(:primitive_type_is_basic?).returns(false) | ||
end | ||
|
||
def expect_type_string_elem_type(attr_details) | ||
type_string = "string" | ||
helper.expects(:get_primitive_type_string).with(attr_details).returns(type_string) | ||
result =helper.create_html_fault_model_element_type(pre, attribute, attr_details) | ||
result.should eq([ "<span class='blue'>#{type_string}</span> <span class='bold'>#{attribute}</span>"]) | ||
end | ||
|
||
it "returns the string element if primitive type is nilclass" do | ||
attr_details = {:primitive => "nilclass"} | ||
expect_type_string_elem_type(attr_details) | ||
end | ||
|
||
["NILCLASS", "Nilclass", "BLA"].each do |primitive| | ||
it "returns the string type is primitive is basic but not nilclass" do | ||
attr_details = {:primitive => primitive} | ||
helper.expects(:primitive_type_is_basic?).with(attr_details).returns(true) | ||
expect_type_string_elem_type(attr_details) | ||
end | ||
end | ||
|
||
["NILCLASS", "Nilclass", "BLA"].each do |primitive| | ||
it "returns the complex type if not basic and not nilclass" do | ||
attr_details = {:primitive => primitive} | ||
member_type = "SomeMemberType" | ||
expected= "Some expected string" | ||
helper.expects(:primitive_type_is_basic?).with(attr_details).returns(false) | ||
helper.expects(:get_member_type_string).with(attr_details).returns(member_type) | ||
helper.expects(:create_fault_model_complex_element_type).with(pre, member_type, attribute, true ).returns(expected) | ||
result =helper.create_html_fault_model_element_type(pre, attribute, attr_details) | ||
result.should eq(expected) | ||
end | ||
end | ||
|
||
end | ||
|
||
end |
108 changes: 108 additions & 0 deletions
108
spec/app/helpers/washout_builder_method_arguments_helper_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
require 'spec_helper' | ||
|
||
describe WashoutBuilderMethodArgumentsHelper, :type => :helper do | ||
let!(:xml) { Builder::XmlMarkup.new} | ||
|
||
context "create_method_argument_element" do | ||
let(:spacer) { " "} | ||
let(:pre){[]} | ||
let(:param){ mock} | ||
let(:complex_class) {"SomeComplexClass"} | ||
let(:param_type) {"string"} | ||
let(:param_name) {"some_param_name"} | ||
|
||
before(:each) do | ||
param.stubs(:get_complex_class_name).returns(complex_class) | ||
param.stubs(:type).returns(param_type) | ||
param.stubs(:name).returns(param_name) | ||
end | ||
|
||
def expect_method_arg_basic_type(mlen) | ||
use_spacer = mlen > 1 ? true : false | ||
result = helper.create_method_argument_element( pre, param, mlen) | ||
result.should eq(["#{use_spacer ? spacer: ''}<span class='blue'>#{param.type}</span> <span class='bold'>#{param.name}</span>"]) | ||
end | ||
|
||
[0, 1 , 2, 3, 4].each do |mlen| | ||
it "returns a basic type" do | ||
WashoutBuilder::Type::BASIC_TYPES.expects(:include?).with(param.type).returns(true) | ||
expect_method_arg_basic_type(mlen) | ||
end | ||
end | ||
|
||
[0, 1 , 2, 3, 4].each do |mlen| | ||
it "returns array of complex type" do | ||
WashoutBuilder::Type::BASIC_TYPES.expects(:include?).with(param.type).returns(false) | ||
param.expects(:multiplied).returns(true) | ||
use_spacer = mlen > 1 ? true : false | ||
result = helper.create_method_argument_element( pre, param, mlen) | ||
result.should eq( ["#{use_spacer ? spacer: ''}<a href='##{complex_class}'><span class='lightBlue'>Array of #{complex_class}</span></a> <span class='bold'>#{param.name}</span>"]) | ||
end | ||
end | ||
|
||
[0, 1 , 2, 3, 4].each do |mlen| | ||
it "returns simple complex type" do | ||
WashoutBuilder::Type::BASIC_TYPES.expects(:include?).with(param.type).returns(false) | ||
param.expects(:multiplied).returns(false) | ||
use_spacer = mlen > 1 ? true : false | ||
result = helper.create_method_argument_element( pre, param, mlen) | ||
result.should eq( ["#{use_spacer ? spacer: ''}<a href='##{complex_class}'><span class='lightBlue'>#{complex_class}</span></a> <span class='bold'>#{param.name}</span>"]) | ||
end | ||
end | ||
|
||
|
||
end | ||
|
||
context "create_argument_element_spacer" do | ||
|
||
it "returns only the ) in bold " do | ||
result = helper.create_argument_element_spacer(xml, 0, 1) | ||
xml.target!.should eq("<span class=\"bold\">)</span>") | ||
end | ||
|
||
it "returns only the span with comma" do | ||
result = helper.create_argument_element_spacer(xml, -2, 1) | ||
xml.target!.should eq("<span>, </span>") | ||
end | ||
|
||
it "returns only the span with comma and a break " do | ||
result = helper.create_argument_element_spacer(xml, 1, 3) | ||
xml.target!.should eq("<span>, </span><br/>") | ||
end | ||
|
||
it "returns a break and a ) sign " do | ||
result = helper.create_argument_element_spacer(xml, 2, 3) | ||
xml.target!.should eq("<br/><span class=\"bold\">)</span>") | ||
end | ||
|
||
[3, 4, 4, 5, 6].each do |j_value| | ||
it "returns only the span with comma " do | ||
result = helper.create_argument_element_spacer(xml, j_value, 3) | ||
xml.target!.should eq("<br/>") | ||
end | ||
end | ||
|
||
|
||
|
||
end | ||
|
||
context "create_html_public_method_arguments" do | ||
let(:pre) {[]} | ||
let(:element) {mock} | ||
let(:second_element){mock} | ||
|
||
it "returns only the span with comma " do | ||
input = [element, second_element] | ||
|
||
helper.stubs(:create_method_argument_element).returns("bla") | ||
helper.stubs(:create_argument_element_spacer).returns("blabla") | ||
result = helper. create_html_public_method_arguments(xml, pre, input) | ||
xml.target!.should eq("<br/>") | ||
end | ||
|
||
end | ||
|
||
|
||
|
||
|
||
end |
Oops, something went wrong.