-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c2c44e
commit c97541c
Showing
3 changed files
with
79 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,30 +63,53 @@ | |
|
||
expect(answer).to eq("[email protected]") | ||
expect(prompt.output.string).to eq([ | ||
"What is your email? ", | ||
"\e[2K\e[1GWhat is your email? w", | ||
"\e[2K\e[1GWhat is your email? wr", | ||
"\e[2K\e[1GWhat is your email? wro", | ||
"\e[2K\e[1GWhat is your email? wron", | ||
"\e[2K\e[1GWhat is your email? wrong", | ||
"\e[2K\e[1GWhat is your email? wrong\n", | ||
"\e[31m>>\e[0m Your answer is invalid (must match :email)\e[1A", | ||
"\e[2K\e[1G", | ||
"What is your email? ", | ||
"\e[2K\e[1GWhat is your email? p", | ||
"\e[2K\e[1GWhat is your email? p@", | ||
"\e[2K\e[1GWhat is your email? p@m", | ||
"\e[2K\e[1GWhat is your email? p@m.", | ||
"\e[2K\e[1GWhat is your email? [email protected]", | ||
"\e[2K\e[1GWhat is your email? [email protected]", | ||
"\e[2K\e[1GWhat is your email? [email protected]", | ||
"\e[2K\e[1GWhat is your email? [email protected]\n", | ||
"\e[2K\e[1G", | ||
"\e[1A\e[2K\e[1G", | ||
"What is your email? \e[[email protected]\e[0m\n" | ||
].join) | ||
"What is your email? ", | ||
"\e[2K\e[1GWhat is your email? w", | ||
"\e[2K\e[1GWhat is your email? wr", | ||
"\e[2K\e[1GWhat is your email? wro", | ||
"\e[2K\e[1GWhat is your email? wron", | ||
"\e[2K\e[1GWhat is your email? wrong", | ||
"\e[2K\e[1GWhat is your email? wrong\n", | ||
"\e[31m>>\e[0m Your answer is invalid (must match :email)\e[1A", | ||
"\e[2K\e[1G", | ||
"What is your email? ", | ||
"\e[2K\e[1GWhat is your email? p", | ||
"\e[2K\e[1GWhat is your email? p@", | ||
"\e[2K\e[1GWhat is your email? p@m", | ||
"\e[2K\e[1GWhat is your email? p@m.", | ||
"\e[2K\e[1GWhat is your email? [email protected]", | ||
"\e[2K\e[1GWhat is your email? [email protected]", | ||
"\e[2K\e[1GWhat is your email? [email protected]", | ||
"\e[2K\e[1GWhat is your email? [email protected]\n", | ||
"\e[2K\e[1G", | ||
"\e[1A\e[2K\e[1G", | ||
"What is your email? \e[[email protected]\e[0m\n" | ||
].join) | ||
end | ||
|
||
let(:expected_custom_validation_message) { [ | ||
"What is your email? ", | ||
"\e[2K\e[1GWhat is your email? w", | ||
"\e[2K\e[1GWhat is your email? wr", | ||
"\e[2K\e[1GWhat is your email? wro", | ||
"\e[2K\e[1GWhat is your email? wron", | ||
"\e[2K\e[1GWhat is your email? wrong", | ||
"\e[2K\e[1GWhat is your email? wrong\n", | ||
"\e[31m>>\e[0m Not an email!\e[1A", | ||
"\e[2K\e[1G", | ||
"What is your email? ", | ||
"\e[2K\e[1GWhat is your email? p", | ||
"\e[2K\e[1GWhat is your email? p@", | ||
"\e[2K\e[1GWhat is your email? p@m", | ||
"\e[2K\e[1GWhat is your email? p@m.", | ||
"\e[2K\e[1GWhat is your email? [email protected]", | ||
"\e[2K\e[1GWhat is your email? [email protected]", | ||
"\e[2K\e[1GWhat is your email? [email protected]", | ||
"\e[2K\e[1G", | ||
"\e[1A\e[2K\e[1G", | ||
"What is your email? \e[[email protected]\e[0m\n" | ||
].join } | ||
|
||
it "provides custom error message for wrong input" do | ||
prompt.input << "wrong\n[email protected]" | ||
prompt.input.rewind | ||
|
@@ -95,15 +118,37 @@ | |
q.messages[:valid?] = "Not an email!" | ||
end | ||
|
||
expect(answer).to eq("[email protected]") | ||
expect(prompt.output.string).to eq(expected_custom_validation_message) | ||
end | ||
|
||
it "provides custom error message for wrong input by keyword parameter instead of passing by block" do | ||
prompt.input << "wrong\n[email protected]" | ||
prompt.input.rewind | ||
|
||
answer = prompt.ask("What is your email?", validate: :email, | ||
messages: { valid?: 'Not an email!' }) | ||
|
||
expect(answer).to eq("[email protected]") | ||
expect(prompt.output.string).to eq(expected_custom_validation_message) | ||
end | ||
|
||
it "keeps the default messages after adding only one custom message" do | ||
prompt.input << "\np\n[email protected]" | ||
prompt.input.rewind | ||
|
||
answer = prompt.ask("What is your email?", required: true, validate: :email, | ||
messages: { valid?: 'Not an email!' }) | ||
|
||
expect(answer).to eq("[email protected]") | ||
expect(prompt.output.string).to eq([ | ||
"What is your email? ", | ||
"\e[2K\e[1GWhat is your email? w", | ||
"\e[2K\e[1GWhat is your email? wr", | ||
"\e[2K\e[1GWhat is your email? wro", | ||
"\e[2K\e[1GWhat is your email? wron", | ||
"\e[2K\e[1GWhat is your email? wrong", | ||
"\e[2K\e[1GWhat is your email? wrong\n", | ||
"\e[2K\e[1GWhat is your email? \n", | ||
"\e[31m>>\e[0m Value must be provided\e[1A", | ||
"\e[2K\e[1G", | ||
"What is your email? ", | ||
"\e[2K\e[1GWhat is your email? p", | ||
"\e[2K\e[1GWhat is your email? p\n", | ||
"\e[31m>>\e[0m Not an email!\e[1A", | ||
"\e[2K\e[1G", | ||
"What is your email? ", | ||
|