Skip to content

Commit 776a9b0

Browse files
Added new test cases
1 parent a2f5b75 commit 776a9b0

File tree

4 files changed

+74
-59
lines changed

4 files changed

+74
-59
lines changed

mailboxvalidator_ruby.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
77
s.description = "Enable users to block disposal email, detect free email and validate if an email is valid"
88
s.author = "MailboxValidator"
99
s.email = 'support@mailboxvalidator'
10-
s.files = ["lib/mailboxvalidator_ruby.rb","test/test.rb","README.rdoc"]
10+
s.files = ["lib/mailboxvalidator_ruby.rb","spec/mailboxvalidator_ruby_webservice_spec.rb","spec/spec_helper.rb","README.rdoc"]
1111
s.homepage = 'https://www.mailboxvalidator.com/ruby'
1212
s.license = 'MIT'
1313
end
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2+
3+
describe "MailboxvalidatorRuby" do
4+
it "work correctly with invalid api key" do
5+
mbv = MailboxValidator::MBV.new()
6+
mbv.apikey = $api_key
7+
mbv.query_single('[email protected]')
8+
expect(mbv.result.error_message).to eq 'API key not found.'
9+
end
10+
11+
it "work correctly with api key exists" do
12+
if $api_key == 'YOUR_API_KEY'
13+
print "/*
14+
* You could enter a MailboxValidator API Key in spec/spec_helper.rb
15+
* for real web service calling test.
16+
*
17+
* You could sign up for a free API key at https://www.mailboxvalidator.com/plans#api
18+
* if you do not have one.
19+
*/"
20+
expect($api_key).to eq 'YOUR_API_KEY'
21+
else
22+
expect($api_key).to_not eq 'YOUR_API_KEY'
23+
end
24+
end
25+
26+
it "work correctly with validate email" do
27+
mbv = MailboxValidator::MBV.new()
28+
mbv.apikey = $api_key
29+
mbv.query_single('[email protected]')
30+
if $api_key == 'YOUR_API_KEY'
31+
expect(mbv.result.error_code).to eq '101'
32+
else
33+
expect(mbv.result.status).to eq 'False'
34+
end
35+
end
36+
37+
it "work correctly with disposable email" do
38+
mbv = MailboxValidator::MBV.new()
39+
mbv.apikey = $api_key
40+
mbv.disposable_email('[email protected]')
41+
if $api_key == 'YOUR_API_KEY'
42+
expect(mbv.result.error_code).to eq '101'
43+
else
44+
expect(mbv.result.status).to eq 'True'
45+
end
46+
end
47+
48+
it "work correctly with free email" do
49+
mbv = MailboxValidator::MBV.new()
50+
mbv.apikey = $api_key
51+
mbv.free_email('[email protected]')
52+
if $api_key == 'YOUR_API_KEY'
53+
expect(mbv.result.error_code).to eq '101'
54+
else
55+
expect(mbv.result.status).to eq 'False'
56+
end
57+
end
58+
59+
end

spec/spec_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2+
$LOAD_PATH.unshift(File.dirname(__FILE__))
3+
require 'rspec'
4+
require 'mailboxvalidator_ruby'
5+
6+
# Requires supporting files with custom matchers and macros, etc,
7+
# in ./support/ and its subdirectories.
8+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9+
10+
RSpec.configure do |config|
11+
12+
end
13+
14+
$api_key = 'YOUR_API_KEY'

test/test.rb

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)