File tree Expand file tree Collapse file tree
1_Introduction/3_Assigning_data Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11variable_types = 3
22language = 'Ruby'
33learned = true
4-
5- puts variable_types
6- puts language
7- puts learned
Original file line number Diff line number Diff line change 11require 'rspec'
22
33describe 'Your code' do
4+ [ [ 'solution::code' ] ]
45
5- describe do
6- before do
7- allow ( $stdout) . to receive ( :puts ) { '' }
8- allow ( $stdout) . to receive ( :p ) { '' }
9- allow ( $stdout) . to receive ( :print ) { '' }
6+ {
7+ variable_types : 3 ,
8+ language : 'Ruby' ,
9+ learned : true
10+ } . each do |variable , value |
11+ it "defines a variable with name \" #{ variable } \" " do
12+ expect ( local_variables . include? ( variable ) ) . to be true
1013 end
1114
12- it 'defines a variable "variable_types" with the value 3' do
13- [ [ 'solution::code' ] ]
14- expect ( !!defined? ( variable_types ) ) . to be true
15- expect ( variable_types ) . to eq 3
16- end
17-
18- it 'defines a variable "language" with the value \'Ruby\'' do
19- [ [ 'solution::code' ] ]
20- expect ( !!defined? ( language ) ) . to be true
21- expect ( language ) . to eq 'Ruby'
22- end
15+ if local_variables . include? ( variable )
16+ displayed_value = value . is_a? ( String ) ? "\" #{ value } \" " : value
2317
24- it 'defines a variable "learned" with the value true' do
25- [ [ 'solution::code' ] ]
26- expect ( !!defined? ( learned ) ) . to be true
27- expect ( learned ) . to eq true
18+ it "defines a variable \" #{ variable } \" with the value #{ displayed_value } " do
19+ expect ( eval ( variable . to_s ) ) . to eq value
20+ end
2821 end
2922 end
30-
31- it 'puts the values of all defined variables to the standard output' do
32- expect ( $stdout) . to receive ( :puts ) . with ( 3 )
33- expect ( $stdout) . to receive ( :puts ) . with ( 'Ruby' )
34- expect ( $stdout) . to receive ( :puts ) . with ( true )
35- [ [ 'solution::code' ] ]
36- end
3723end
Original file line number Diff line number Diff line change @@ -69,6 +69,4 @@ Set the following variables:
6969` language ` to the string * 'Ruby'* and
7070` learned ` to the boolean * true*
7171
72- and print out each variable's value by using the * puts* method!
73-
7472---
You can’t perform that action at this time.
0 commit comments