|
1 | 1 | require "rails_helper" |
2 | 2 |
|
3 | | -RSpec.describe PhoneNumberHelper do |
4 | | - describe "phone number helper" do |
5 | | - include PhoneNumberHelper |
6 | | - |
7 | | - context "validates phone number" do |
8 | | - it "with empty string" do |
9 | | - valid, error = valid_phone_number("") |
10 | | - expect(valid).to be(true) |
11 | | - expect(error).to be_nil |
12 | | - end |
| 3 | +RSpec.describe PhoneNumberHelper, type: :helper do |
| 4 | + context "validates phone number" do |
| 5 | + it "with empty string" do |
| 6 | + valid, error = valid_phone_number("") |
| 7 | + expect(valid).to be(true) |
| 8 | + expect(error).to be_nil |
| 9 | + end |
13 | 10 |
|
14 | | - it "with 10 digit phone number prepended with US country code" do |
15 | | - valid, error = valid_phone_number("+12223334444") |
16 | | - expect(valid).to be(true) |
17 | | - expect(error).to be_nil |
18 | | - end |
| 11 | + it "with 10 digit phone number prepended with US country code" do |
| 12 | + valid, error = valid_phone_number("+12223334444") |
| 13 | + expect(valid).to be(true) |
| 14 | + expect(error).to be_nil |
| 15 | + end |
19 | 16 |
|
20 | | - it "with 10 digit phone number prepended with US country code without the plus sign" do |
21 | | - valid, error = valid_phone_number("12223334444") |
22 | | - expect(valid).to be(true) |
23 | | - expect(error).to be_nil |
24 | | - end |
| 17 | + it "with 10 digit phone number prepended with US country code without the plus sign" do |
| 18 | + valid, error = valid_phone_number("12223334444") |
| 19 | + expect(valid).to be(true) |
| 20 | + expect(error).to be_nil |
| 21 | + end |
25 | 22 |
|
26 | | - it "with 10 phone number with spaces" do |
27 | | - valid, error = valid_phone_number("222 333 4444") |
28 | | - expect(valid).to be(true) |
29 | | - expect(error).to be_nil |
30 | | - end |
| 23 | + it "with 10 phone number with spaces" do |
| 24 | + valid, error = valid_phone_number("222 333 4444") |
| 25 | + expect(valid).to be(true) |
| 26 | + expect(error).to be_nil |
| 27 | + end |
31 | 28 |
|
32 | | - it "with 10 phone number with parentheses" do |
33 | | - valid, error = valid_phone_number("(222)3334444") |
34 | | - expect(valid).to be(true) |
35 | | - expect(error).to be_nil |
36 | | - end |
| 29 | + it "with 10 phone number with parentheses" do |
| 30 | + valid, error = valid_phone_number("(222)3334444") |
| 31 | + expect(valid).to be(true) |
| 32 | + expect(error).to be_nil |
| 33 | + end |
37 | 34 |
|
38 | | - it "with 10 phone number with dashes" do |
39 | | - valid, error = valid_phone_number("222-333-4444") |
40 | | - expect(valid).to be(true) |
41 | | - expect(error).to be_nil |
42 | | - end |
| 35 | + it "with 10 phone number with dashes" do |
| 36 | + valid, error = valid_phone_number("222-333-4444") |
| 37 | + expect(valid).to be(true) |
| 38 | + expect(error).to be_nil |
| 39 | + end |
43 | 40 |
|
44 | | - it "with 10 phone number with dots" do |
45 | | - valid, error = valid_phone_number("222.333.4444") |
46 | | - expect(valid).to be(true) |
47 | | - expect(error).to be_nil |
48 | | - end |
| 41 | + it "with 10 phone number with dots" do |
| 42 | + valid, error = valid_phone_number("222.333.4444") |
| 43 | + expect(valid).to be(true) |
| 44 | + expect(error).to be_nil |
49 | 45 | end |
| 46 | + end |
50 | 47 |
|
51 | | - context "invalidates phone number" do |
52 | | - it "with incorrect country code" do |
53 | | - valid, error = valid_phone_number("+22223334444") |
54 | | - expect(valid).to be(false) |
55 | | - expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)") |
56 | | - end |
| 48 | + context "invalidates phone number" do |
| 49 | + it "with incorrect country code" do |
| 50 | + valid, error = valid_phone_number("+22223334444") |
| 51 | + expect(valid).to be(false) |
| 52 | + expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)") |
| 53 | + end |
57 | 54 |
|
58 | | - it "with short phone number" do |
59 | | - valid, error = valid_phone_number("+122") |
60 | | - expect(valid).to be(false) |
61 | | - expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)") |
62 | | - end |
| 55 | + it "with short phone number" do |
| 56 | + valid, error = valid_phone_number("+122") |
| 57 | + expect(valid).to be(false) |
| 58 | + expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)") |
| 59 | + end |
63 | 60 |
|
64 | | - it "with long phone number" do |
65 | | - valid, error = valid_phone_number("+12223334444555") |
66 | | - expect(valid).to be(false) |
67 | | - expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)") |
68 | | - end |
| 61 | + it "with long phone number" do |
| 62 | + valid, error = valid_phone_number("+12223334444555") |
| 63 | + expect(valid).to be(false) |
| 64 | + expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)") |
69 | 65 | end |
70 | 66 | end |
71 | 67 | end |
0 commit comments