Skip to content

Commit

Permalink
Merge branch 'release/tests-coverage'
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed Nov 21, 2014
2 parents 5406b54 + 91fd222 commit 2c11c77
Show file tree
Hide file tree
Showing 9 changed files with 460 additions and 16 deletions.
10 changes: 4 additions & 6 deletions app/helpers/washout_builder_method_list_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ def create_return_complex_type_list_html(xml, complex_class, builder_out)
def create_return_type_list_html(xml, output)
unless output.nil?
if output.nil?
xml.span("class" => "pre") { |sp| sp << "void" }
else
complex_class = output[0].get_complex_class_name
if WashoutBuilder::Type::BASIC_TYPES.include?(output[0].type)
xml.span("class" => "pre") { |xml| xml.span("class" => "blue") { |sp| sp << "#{output[0].type}" } }
else
create_return_complex_type_html(xml, complex_class, output) unless complex_class.nil?
end
else
xml.span("class" => "pre") { |sp| sp << "void" }
end
end
end
end
6 changes: 4 additions & 2 deletions app/helpers/washout_builder_method_return_type_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ def create_html_public_method_return_type(xml,pre, output)
if WashoutBuilder::Type::BASIC_TYPES.include?(output[0].type)
xml.span("class" => "blue") { |y| y<< "#{output[0].type}" }
else
complex_return_type = output[0].multiplied == false ? "#{complex_class}" : "Array of #{complex_class}"
pre << "<a href='##{complex_class}'><span class='lightBlue'>#{complex_return_type}</span></a>" unless complex_class.nil?
unless complex_class.nil?
complex_return_type = output[0].multiplied == false ? "#{complex_class}" : "Array of #{complex_class}"
pre << "<a href='##{complex_class}'><span class='lightBlue'>#{complex_return_type}</span></a>"
end
end
else
pre << "void"
Expand Down
80 changes: 77 additions & 3 deletions spec/app/helpers/washout_builder_complex_type_helper_spec.rb
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>&nbsp;<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>&nbsp;<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>&nbsp;<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 spec/app/helpers/washout_builder_fault_type_helper_spec.rb
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>&nbsp;<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>&nbsp;<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 spec/app/helpers/washout_builder_method_arguments_helper_spec.rb
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) { "&nbsp;&nbsp;&nbsp;&nbsp;"}
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>&nbsp;<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>&nbsp;<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>&nbsp;<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
Loading

0 comments on commit 2c11c77

Please sign in to comment.