Skip to content

Commit

Permalink
devcontainers, modernize rspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pcai committed Jul 8, 2024
1 parent 1902511 commit 1141fa1
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 65 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby
{
"name": "Ruby",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/ruby:1-3.3-bullseye"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "ruby --version",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ source 'https://rubygems.org/'
gemspec

group :development do
gem 'rspec', '<3.0'
gem 'guard', '2.12.6'
gem 'guard-rspec'
gem 'rspec'
gem 'rb-inotify', :require => false
gem 'turn'
gem "pry-nav"
Expand Down
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
require 'turn/autorun'
require_relative 'xml_matcher'

RSpec.configure do |rspec|
rspec.mock_with :rspec do |mocks|
RSpec.configure do |config|
config.mock_with :rspec do |mocks|
mocks.yield_receiver_to_any_instance_implementation_blocks = false
end
config.raise_errors_for_deprecations!
end

Turn.config.format = :outline
Expand Down
16 changes: 7 additions & 9 deletions spec/unit/ews_folder_operations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
require_relative '../spec_helper'

describe "Operations on Exchange Data Services" do

before do
con = double('Connection')
@ews = Viewpoint::EWS::SOAP::ExchangeWebService.new con,
{:server_version => Viewpoint::EWS::SOAP::VERSION_2010_SP2}
@ews.stub(:do_soap_request)
end

it "generates CreateFolder XML" do
@ews.should_receive(:do_soap_request).
expect(@ews).to receive(:do_soap_request).
with(match_xml(load_soap("create_folder", :request)))

fname = "Test Folder"
Expand All @@ -20,15 +18,15 @@
end

it "generates CopyFolder XML" do
@ews.should_receive(:do_soap_request).
expect(@ews).to receive(:do_soap_request).
with(match_xml(load_soap("copy_folder", :request)))

tofid = {:id => 'dest_folder_id'}
@ews.copy_folder tofid, [:id => 'src_folder_id']
end

it "generates DeleteFolder XML" do
@ews.should_receive(:do_soap_request).
expect(@ews).to receive(:do_soap_request).
with(match_xml(load_soap("delete_folder", :request)))

fid = "test_folder_id"
Expand All @@ -38,7 +36,7 @@
end

it "generates FindFolder XML" do
@ews.should_receive(:do_soap_request).
expect(@ews).to receive(:do_soap_request).
with(match_xml(load_soap("find_folder", :request)))

fname = "Test Folder"
Expand All @@ -65,7 +63,7 @@
end

it "generates GetFolder XML" do
@ews.should_receive(:do_soap_request).
expect(@ews).to receive(:do_soap_request).
with(match_xml(load_soap("get_folder", :request)))

opts = { :folder_ids => [{:id => :msgfolderroot}],
Expand All @@ -91,15 +89,15 @@
end

it "generates MoveFolder XML" do
@ews.should_receive(:do_soap_request).
expect(@ews).to receive(:do_soap_request).
with(match_xml(load_soap("move_folder", :request)))

tofid = {:id => 'dest_folder_id'}
@ews.move_folder tofid, [:id => 'src_folder_id']
end

it "generates EmptyFolder XML" do
@ews.should_receive(:do_soap_request).
expect(@ews).to receive(:do_soap_request).
with(match_xml(load_soap("empty_folder", :request)))

fid = "test_folder_id"
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/ews_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
it 'parses a successful response' do
soap_resp = load_soap 'find_folder', :response
resp = Viewpoint::EWS::SOAP::EwsParser.new(soap_resp).parse
resp.body.should == success_body
expect(resp.body).to eq success_body
end

it 'parses an unsuccessful response' do
soap_resp = load_soap 'find_folder_error', :response
resp = Viewpoint::EWS::SOAP::EwsParser.new(soap_resp).parse
resp.body.should == error_body
expect(resp.body).to eq error_body
end

end
10 changes: 5 additions & 5 deletions spec/unit/ews_rooms_operations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
con = double('Connection')
@ews = Viewpoint::EWS::SOAP::ExchangeWebService.new con,
{:server_version => Viewpoint::EWS::SOAP::VERSION_2010_SP2}
@ews.stub(:do_soap_request)
allow(@ews).to receive(:do_soap_request)
end

it "generates GetRooms XML" do
@ews.should_receive(:do_soap_request) do |request_document|
expect(@ews).to receive(:do_soap_request) do |request_document|
doc = request_document.to_s.gsub(%r{>\s+}, '>')
doc.should eq load_soap("get_rooms", :request)
expect(doc).to eq load_soap("get_rooms", :request)
end
@ews.get_rooms '[email protected]'
end

it "generates GetRoomLists XML" do
@ews.should_receive(:do_soap_request) do |request_document|
expect(@ews).to receive(:do_soap_request) do |request_document|
doc = request_document.to_s.gsub(%r{>\s+}, '>')
doc.should eq load_soap("get_room_lists", :request)
expect(doc).to eq load_soap("get_room_lists", :request)
end.and_return(double(:resp))
@ews.get_room_lists
end
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/ews_soap_free_busy_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
let(:resp) { ews.parse_soap_response(ERROR_INVALID_SMTP_ADDRESS, :response_class => described_class) }

it "should deliver the error code" do
resp.code.should eq "ErrorInvalidSmtpAddress"
expect(resp.code).to eq "ErrorInvalidSmtpAddress"
end

it "should extract the response message" do
Expand All @@ -58,7 +58,7 @@
}}
]
}
resp.response_message.should == extracted_response_message
expect(resp.response_message).to eq extracted_response_message
end
end

Expand Down Expand Up @@ -106,11 +106,11 @@
let(:resp) { ews.parse_soap_response(CALENDAR_EVENT_ARRAY, :response_class => described_class) }

it "response should be successful" do
resp.status.should eq "Success"
expect(resp.status).to eq "Success"
end

it "the calendar_event_array should have one element" do
resp.calendar_event_array.should have(1).items
expect(resp.calendar_event_array.length).to eq 1
end
end

Expand Down Expand Up @@ -141,11 +141,11 @@
let(:resp) { ews.parse_soap_response(EMPTY_RESPONSE, :response_class => described_class) }

it "response should be success" do
resp.status.should eq "Success"
expect(resp.status).to eq "Success"
end

it "the calendar_event_array should be an empty list" do
resp.calendar_event_array.should eq []
expect(resp.calendar_event_array).to eq []
end
end

Expand Down
24 changes: 12 additions & 12 deletions spec/unit/folder_accessors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def self.folders
ews = double("ews")
@ecli = double("EWSClient")
@ecli.extend subject
@ecli.stub(:ews) {ews}
@ecli.stub(:merge_restrictions!)
allow(@ecli).to receive(:ews).and_return ews
allow(@ecli).to receive(:merge_restrictions!)
end

context "ensure FolderAccessors methods are returning good data" do
Expand All @@ -24,14 +24,14 @@ def self.folders
resp.status = 'Success'
rhash = {:elems => {:root_folder => {:elems => [{:folders =>{:elems => ResponseObjects.folders}}]}}}
resp.response_message = rhash
@ecli.ews.stub(:find_folder).with(an_instance_of(Hash)) { resp }
allow(@ecli.ews).to receive(:find_folder).with(an_instance_of(Hash)).and_return resp
cbn = double("ClassByName")
cbn.stub(:new) { double("FolderMock") }
@ecli.stub(:class_by_name) { cbn }
allow(cbn).to receive(:new).and_return double("FolderMock")
allow(@ecli).to receive(:class_by_name).and_return cbn
end

it '#find_folders should return folders' do
@ecli.folders.should be_instance_of(Array)
expect(@ecli.folders).to be_instance_of(Array)
end
end
context "methods utilizing ExchangeWebService#get_folder" do
Expand All @@ -40,13 +40,13 @@ def self.folders
resp.status = 'Success'
rhash = {:elems => {:folders =>{:elems => ResponseObjects.folders}}}
resp.response_message = rhash
@ecli.ews.stub(:get_folder).with(an_instance_of(Hash)) { resp }
allow(@ecli.ews).to receive(:get_folder).with(an_instance_of(Hash)).and_return resp
cbn = double("ClassByName")
cbn.stub(:new) { double("Folder") }
@ecli.stub(:class_by_name) { cbn }
allow(cbn).to receive(:new).and_return double("Folder")
allow(@ecli).to receive(:class_by_name).and_return cbn
end
it '#get_folder should return a Folder' do
@ecli.get_folder(:inbox).should be_instance_of(RSpec::Mocks::Mock)
expect(@ecli.get_folder(:inbox)).to be_a(RSpec::Mocks::Double)
end
end
end
Expand All @@ -55,8 +55,8 @@ def self.folders
before do
resp = OpenStruct.new
resp.status = 'Failure'
@ecli.ews.stub(:find_folder).with(an_instance_of(Hash)) { resp }
@ecli.ews.stub(:get_folder).with(an_instance_of(Hash)) { resp }
allow(@ecli.ews).to receive(:find_folder).with(an_instance_of(Hash)).and_return resp
allow(@ecli.ews).to receive(:get_folder).with(an_instance_of(Hash)).and_return resp
end
it '#find_folders should raise an exception' do
expect {
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/item_accessors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.folders
ews = double("ews")
@ecli = double("EWSClient")
@ecli.extend subject
@ecli.stub(:ews) {ews}
allow(@ecli).to receive(:ews).and_return(ews)
end

context "ensure that exceptions are being raised" do
Expand All @@ -22,7 +22,7 @@ def self.folders
rm = OpenStruct.new
rm.status = 'Failure'
resp.response_messages = [rm]
@ecli.ews.stub(:get_item).with(an_instance_of(Hash)) { resp }
allow(@ecli.ews).to receive(:get_item).with(an_instance_of(Hash)).and_return resp
end
it '#get_item should raise an exception' do
expect {
Expand All @@ -42,7 +42,7 @@ def call_get_item_args(*args)
it "should handle an :occurrence_item_id hash" do
occurrence_item_id = {:occurrence_item_id => {:recurring_master_id => 'rid1', :change_key => 'ck', :instance_index => 1}}
result = GetItemArgsAccessor.new.call_get_item_args(occurrence_item_id, {})
result[:item_ids].should eq [occurrence_item_id]
expect(result[:item_ids]).to eq [occurrence_item_id]
end

it "should handle an Array of :occurrence_item_id hashes" do
Expand All @@ -52,19 +52,19 @@ def call_get_item_args(*args)
{:occurrence_item_id => {:recurring_master_id => 'rid3', :change_key => 'ck3', :instance_index => 3}},
]
result = GetItemArgsAccessor.new.call_get_item_args(occurrences, {})
result[:item_ids].should eq occurrences
expect(result[:item_ids]).to eq occurrences
end

it "should handle an :id hash" do
id = {:id => 'id1', :change_key => 'ck1'}
result = GetItemArgsAccessor.new.call_get_item_args(id, {})
result[:item_ids].should eq [{:item_id => {:id => 'id1', :change_key => 'ck1'}}]
expect(result[:item_ids]).to eq [{:item_id => {:id => 'id1', :change_key => 'ck1'}}]
end

it "should handle an Array of id strings" do
ids = ['id1', 'id2', 'id3']
result = GetItemArgsAccessor.new.call_get_item_args(ids, {})
result[:item_ids].should eq [{:item_id=>{:id => 'id1'}},{:item_id=>{:id => 'id2'}},{:item_id=>{:id => 'id3'}}]
expect(result[:item_ids]).to eq [{:item_id=>{:id => 'id1'}},{:item_id=>{:id => 'id2'}},{:item_id=>{:id => 'id3'}}]
end
end

Expand Down
5 changes: 2 additions & 3 deletions spec/unit/mailbox_accessors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
context "#get_user_availability" do

it "should care about timezones" do
Viewpoint::EWS::SOAP::ExchangeWebService.any_instance.
should_receive(:do_soap_request) do |request_document|
request_document.at_xpath('//soap:Envelope/soap:Body//t:TimeZone').to_s.should eq timezone_request
expect_any_instance_of(Viewpoint::EWS::SOAP::ExchangeWebService).to receive(:do_soap_request) do |request_document|
expect(request_document.at_xpath('//soap:Envelope/soap:Body//t:TimeZone').to_s).to eq timezone_request
end.
and_return(double(:resp, :status => 'Success'))

Expand Down
15 changes: 6 additions & 9 deletions spec/unit/meeting_accessors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
end

it "should form valid accept item request" do
Viewpoint::EWS::SOAP::ExchangeWebService.any_instance.
should_receive(:do_soap_request) do |request_document|
request_document.at_xpath('//soap:Envelope/soap:Body').to_s.should eq create_item_request
expect_any_instance_of(Viewpoint::EWS::SOAP::ExchangeWebService).to receive(:do_soap_request) do |request_document|
expect(request_document.at_xpath('//soap:Envelope/soap:Body').to_s).to eq create_item_request
end.
and_return(double(:resp, :status => 'Success'))

Expand All @@ -54,9 +53,8 @@
end

it "should form valid accept item request" do
Viewpoint::EWS::SOAP::ExchangeWebService.any_instance.
should_receive(:do_soap_request) do |request_document|
request_document.at_xpath('//soap:Envelope/soap:Body').to_s.should eq create_item_request
expect_any_instance_of(Viewpoint::EWS::SOAP::ExchangeWebService).to receive(:do_soap_request) do |request_document|
expect(request_document.at_xpath('//soap:Envelope/soap:Body').to_s).to eq create_item_request
end.
and_return(double(:resp, :status => 'success'))

Expand All @@ -80,9 +78,8 @@
end

it "should form valid accept item request" do
Viewpoint::EWS::SOAP::ExchangeWebService.any_instance.
should_receive(:do_soap_request) do |request_document|
request_document.at_xpath('//soap:Envelope/soap:Body').to_s.should eq create_item_request
expect_any_instance_of(Viewpoint::EWS::SOAP::ExchangeWebService).to receive(:do_soap_request) do |request_document|
expect(request_document.at_xpath('//soap:Envelope/soap:Body').to_s).to eq create_item_request
end.
and_return(double(:resp, :status => 'success'))

Expand Down
Loading

0 comments on commit 1141fa1

Please sign in to comment.