Skip to content

Commit c2a9492

Browse files
committed
Add spec for String concatenation task
1 parent 63589cf commit c2a9492

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

3_Strings/1_Interpolation/solution_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def interpolation_part_of(actual)
4242
interpolation.first
4343
end
4444
end
45+
4546
describe "Your code" do
4647
[['solution::code']]
4748

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,51 @@
11
require 'rspec'
2+
require 'rspec/expectations'
3+
4+
RSpec::Matchers.define :use_multiplication_of_strings do
5+
match { |actual| actual =~ /['"]o['"]\s?\*\s?\d+/ }
6+
7+
failure_message do |actual|
8+
%Q{Your code doesn't use the * method to add the "o"s}
9+
end
10+
end
11+
12+
RSpec::Matchers.define :concat_the_ordinal_number do |expected|
13+
match { |actual| actual =~ /(<<[\(\s]?#{expected}\)?|\.concat[\(\s]#{expected}\(?)/ }
14+
15+
failure_message do |actual|
16+
%Q{Your code doesn't add "#{expected.chr}" by using the ordinal number}
17+
end
18+
end
19+
20+
def code_line
21+
%q{[['solution::code']]}
22+
end
23+
24+
def code
25+
@code ||= eval(code_line)
26+
end
227

328
describe 'Your code' do
29+
it 'creates a String' do
30+
expect(code).to be_a String
31+
end
32+
33+
it 'adds whitespace by using the ordinal number' do
34+
expect(code_line).to concat_the_ordinal_number 32
35+
end
36+
37+
it 'uses the * method to create the "ooooo"' do
38+
expect(code_line).to use_multiplication_of_strings
39+
end
40+
41+
it 'adds an exclamation mark by using the ordinal number' do
42+
expect(code_line).to concat_the_ordinal_number 33
43+
end
44+
445

46+
if code.is_a?(String)
47+
it 'forms the String "Ruby rooooocks!"' do
48+
expect(code.strip).to eq 'Ruby rooooocks!'
49+
end
50+
end
551
end

0 commit comments

Comments
 (0)