Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed Dec 17, 2013
1 parent 0c0e767 commit 72194ab
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 20 deletions.
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ gem 'tzinfo'
gem 'pry'
gem 'simplecov'
gem 'simplecov-summary'

gem 'nori'
gem 'nokogiri'

gem 'capybara', '1.1.4'
gem 'selenium-webdriver', '~> 2.37.0'
gem 'headless'
gem 'capybara-firebug'
gem 'mocha', '~> 0.13.3', :require => false
gem 'factory_girl_rails'
gem 'forgery'
gem 'webmock'
gem 'rspec-instafail'

16 changes: 10 additions & 6 deletions lib/washout_builder/document/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,23 @@ def operations

def input_types
types = []
soap_actions.each do |operation, formats|
(formats[:in]).each do |p|
types << p
unless soap_actions.blank?
soap_actions.each do |operation, formats|
(formats[:in]).each do |p|
types << p
end
end
end
types
end

def output_types
types = []
soap_actions.each do |operation, formats|
(formats[:out]).each do |p|
types << p
unless soap_actions.blank?
soap_actions.each do |operation, formats|
(formats[:out]).each do |p|
types << p
end
end
end
types
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/washout_builder/dispatcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def dispatcher_method
render_views(false)

before(:each) do
WashoutBuilder::Document::Generator.stub(:new).and_return(document)
WashoutBuilder::Document::Generator.stubs(:new).returns(document)
end

it "inits the document generator" do
Expand Down
126 changes: 125 additions & 1 deletion spec/lib/washout_builder/document/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,131 @@

describe WashoutBuilder::Document::Generator do

let(:generator) { FactoryGirl.build(:generator)}
let(:soap_config) { OpenStruct.new(
camelize_wsdl: false,
namespace: "/api/wsdl",
description: "some description"
) }

let(:soap_actions) {
{'dispatcher_method' =>
{:args => nil, :return => nil, :in => [], :out => [], :to => 'dispatcher_method'}
}
}
let(:service_class) { ApiController }
let(:attributes) {
{
:config => soap_config,
:service_class => service_class,
:soap_actions => soap_actions
}}

before(:each) do
@document = WashoutBuilder::Document::Generator.new(attributes)
end

context "initialize" do

it "sets the config " do
@document.config.should eq(soap_config)
end

it "sets the service_class " do
@document.service_class.should eq(service_class)
end

it "sets the soap_actions " do
@document.soap_actions.should eq(soap_actions)
end

end


context "namespace" do
specify { @document.namespace.should eq(soap_config.namespace) }
end

context "endpoint" do
specify { @document.endpoint.should eq(soap_config.namespace.gsub("/wsdl", "/action")) }
end

context "service" do
specify { @document.service.should eq(service_class.name.underscore.gsub("_controller", "").camelize) }
end

context "description" do
specify {@document.service_description.should eq(soap_config.description )}
end

context "operations" do
specify { @document.operations.should eq(soap_actions.map { |operation, formats| operation }) }
end


context "input types" do
let(:expected) { types = []
soap_actions.each do |operation, formats|
(formats[:in]).each do |p|
types << p
end
end
types }

specify { @document.input_types.should eq(expected) }

end

context "output types" do
let(:expected) { types = []
soap_actions.each do |operation, formats|
(formats[:out]).each do |p|
types << p
end
end
types }

specify { @document.output_types.should eq(expected) }

end


context "get_soap_action_names" do

let(:expected) {soap_actions.map { |operation, formats| operation }.map(&:to_s).sort_by { |name| name.downcase }.uniq}

specify { @document.get_soap_action_names.should eq(expected) }


it "returns nil on empty soap actions" do
@document.stubs(:soap_actions).returns(nil)
@document.get_soap_action_names.should eq(nil)
end

end



context "complex types" do

let(:expected){

}


it "returns nil on empty soap actions" do
@document.stubs(:soap_actions).returns(nil)
@document.complex_types.should eq(nil)
end

it "returns nil if no complex types detected" do
@document.complex_types.should eq(nil)
end





end


end
10 changes: 1 addition & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
require 'capybara/rspec'
require 'capybara/rails'
require 'capybara/firebug/rspec'
require 'forgery/forgery'
require 'webmock/rspec'
require 'headless'

Expand All @@ -37,23 +36,16 @@
require 'rspec/expectations'
config.include RSpec::Matchers

# mock framework
# config.mock_with :mocha

#config.include Savon::Spec::Macros
#config.include AbstractController::Translation

config.before(:suite) do
# Reload factories in spec/factories.
FactoryGirl.reload
# Blocks all remote HTTP requests by default, they need to be stubbed.
WebMock.disable_net_connect!(:allow_localhost => true)
if !RUBY_PLATFORM.downcase.include?('darwin') && !ENV['NO_HEADLESS']
Headless.new(reuse: false, destroy_on_exit: false).start
end
end

config.mock_with :rspec
config.mock_with :mocha
config.before(:all) do
WashoutBuilder::Engine.config.wash_out = {
snakecase_input: false,
Expand Down

0 comments on commit 72194ab

Please sign in to comment.