seeing_is_believing 3.0.0.beta.3 → 3.0.0.beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,6 @@
2
2
  require 'spec_helper'
3
3
  require 'stringio'
4
4
  require 'seeing_is_believing'
5
- require 'seeing_is_believing/evaluate_with_eval_in'
6
5
 
7
6
  RSpec.describe SeeingIsBelieving do
8
7
  def method_result(name)
@@ -30,10 +29,6 @@ RSpec.describe SeeingIsBelieving do
30
29
 
31
30
  let(:proving_grounds_dir) { File.expand_path '../../proving_grounds', __FILE__ }
32
31
 
33
- it 'evaluates with EvaluateByMovingFiles by default' do
34
- expect(values_for "`echo 1`").to eq [['"1\n"']] # shows we're not using the only other option (EvaluateWithEvalIn)
35
- end
36
-
37
32
  it 'takes a string and returns a result of the line numbers (counting from 1) and each inspected result from that line' do
38
33
  input = "10+10\n'2'+'2'"
39
34
  expect(invoke(input)[1]).to eq ["20"]
@@ -45,6 +40,23 @@ RSpec.describe SeeingIsBelieving do
45
40
  expect(invoke(input)[1]).to eq ['"NUM"']
46
41
  end
47
42
 
43
+ it 'makes the SiB version info available' do
44
+ expect(invoke('$SiB.ver')[1][0]).to eq SeeingIsBelieving::VERSION.inspect
45
+ end
46
+
47
+ it 'records various useful information on the result' do
48
+ result = invoke '', number_of_captures: 10, filename: 'abc.rb'
49
+ expect(result.sib_version).to eq SeeingIsBelieving::VERSION
50
+ expect(result.ruby_version).to eq RUBY_VERSION
51
+ expect(result.number_of_captures).to eq 10 # TODO: rename to max_captures_per_line ?? (also max_line_captures would prob get renamed if we do this)
52
+ expect(result.num_lines).to eq 1
53
+ expect(result.filename).to eq 'abc.rb'
54
+ end
55
+
56
+ it 'makes the Ruby versino info available' do
57
+ expect(invoke('').ruby_version).to eq RUBY_VERSION
58
+ end
59
+
48
60
  it 'allows uers to pass in their own inspection recorder' do
49
61
  wrapper = lambda { |program, filename, num_captures|
50
62
  SeeingIsBelieving::InspectExpressions.call \
@@ -145,7 +157,7 @@ RSpec.describe SeeingIsBelieving do
145
157
  expect(result.exception.backtrace).to be_a_kind_of Array
146
158
  end
147
159
 
148
- context 'exceptions in exit blocks', t:true do
160
+ context 'exceptions in exit blocks' do
149
161
  # I'm punting on this because there is just no good way to stop that from happening without changing actual behaviour
150
162
  # see https://github.com/JoshCheek/seeing_is_believing/issues/24
151
163
  it 'does not include information about the_matrix in the exception backtraces' do
@@ -368,27 +380,6 @@ RSpec.describe SeeingIsBelieving do
368
380
  ['2']]
369
381
  end
370
382
 
371
- it 'can evaluate under a different ruby executable' do
372
- Dir.chdir proving_grounds_dir do
373
- File.write 'omg-ruby', "#!/usr/bin/env ruby
374
- $LOAD_PATH.unshift '#{File.expand_path '../../lib', __FILE__}'
375
-
376
- require 'seeing_is_believing/event_stream/producer'
377
- sib = SeeingIsBelieving::EventStream::Producer.new($stdout)
378
- sib.record_result(:inspect, 1, /omg/)
379
- sib.finish!
380
- "
381
- File.chmod 0755, 'omg-ruby'
382
- old_path = ENV['PATH']
383
- ENV['PATH'] = "#{proving_grounds_dir}:#{old_path}"
384
- begin
385
- expect(values_for("1", ruby_executable: 'omg-ruby')).to eq [["/omg/"]]
386
- ensure
387
- ENV['PATH'] = old_path
388
- end
389
- end
390
- end
391
-
392
383
  describe 'BEGIN and END' do
393
384
  it 'Executes in the appropriate order' do
394
385
  pending 'not implemented'
@@ -481,41 +472,16 @@ RSpec.describe SeeingIsBelieving do
481
472
  # should ProgramRewriter have some debug options?
482
473
  end
483
474
 
484
- context 'when :evaluator option is set' do
485
- require 'webmock'
486
- WebMock.disable_net_connect!
487
-
488
- include WebMock::API
489
- before { WebMock.reset! }
490
-
491
- it 'can use EvaluateByMovingFiles' do
492
- # shows we're not using the only other option (EvaluateWithEvalIn)
493
- expect(values_for "`echo 1`", evaluator: SeeingIsBelieving::EvaluateByMovingFiles).to eq [['"1\n"']]
494
- end
495
-
496
- it 'can use EvaluateWithEvalIn' do
497
- require 'seeing_is_believing/event_stream/producer'
498
- redirect_url = 'https://example.com/whatever'
499
- api_redirect_url = redirect_url + '.json'
500
-
501
- stream = StringIO.new
502
- producer = SeeingIsBelieving::EventStream::Producer.new(stream)
503
- producer.record_result :inspect, 1, "a"
504
- producer.record_result :inspect, 1, "b"
505
- producer.record_result :inspect, 2, "c"
506
- producer.finish!
507
-
508
- response = { 'lang' => 'whatever',
509
- 'lang_friendly' => 'whatever',
510
- 'code' => 'whatever',
511
- 'output' => stream.string,
512
- 'status' => 'OK (0.012 sec real, 0.013 sec wall, 7 MB, 22 syscalls)'}
513
-
514
- stub_request(:post, 'https://eval.in/').to_return(status: 302, headers: {'Location' => redirect_url})
515
- stub_request(:get, api_redirect_url).to_return(status: 200, body: JSON.dump(response))
516
-
517
- values = values_for "whatever", evaluator: SeeingIsBelieving::EvaluateWithEvalIn
518
- expect(values).to eq [['"a"', '"b"'], ['"c"']]
519
- end
475
+ it 'can deal with exec' do
476
+ result = invoke \
477
+ "1+1\n"\
478
+ "$stdout.puts *1..1000\n"\
479
+ "$stderr.puts *1..1000\n"\
480
+ "exec %(ruby -e '$stdout.puts %[out from exec];
481
+ $stderr.puts %[err from exec]')"
482
+ expect(result[1]).to eq ['2']
483
+ nums = (1..1000).map { |n| "#{n}\n" }.join('')
484
+ expect(result.stdout).to eq "#{nums}out from exec\n"
485
+ expect(result.stderr).to eq "#{nums}err from exec\n"
520
486
  end
521
487
  end
metadata CHANGED
@@ -1,63 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seeing_is_believing
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta.3
4
+ version: 3.0.0.beta.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cheek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-05 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: eval_in
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.1.6
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.1.6
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: parser
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: 2.1.4
19
+ version: '2.2'
34
20
  - - "<"
35
21
  - !ruby/object:Gem::Version
36
- version: '2.3'
22
+ version: '3.0'
37
23
  type: :runtime
38
24
  prerelease: false
39
25
  version_requirements: !ruby/object:Gem::Requirement
40
26
  requirements:
41
27
  - - ">="
42
28
  - !ruby/object:Gem::Version
43
- version: 2.1.4
29
+ version: '2.2'
44
30
  - - "<"
45
31
  - !ruby/object:Gem::Version
46
- version: '2.3'
47
- - !ruby/object:Gem::Dependency
48
- name: webmock
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '1.18'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '1.18'
32
+ version: '3.0'
61
33
  - !ruby/object:Gem::Dependency
62
34
  name: haiti
63
35
  requirement: !ruby/object:Gem::Requirement
@@ -154,11 +126,11 @@ files:
154
126
  - docs/example.gif
155
127
  - docs/for-presentations
156
128
  - docs/frog-brown.png
129
+ - features/deprecated-flags.feature
157
130
  - features/errors.feature
158
131
  - features/examples.feature
159
132
  - features/flags.feature
160
133
  - features/regression.feature
161
- - features/safe.feature
162
134
  - features/support/env.rb
163
135
  - features/xmpfilter-style.feature
164
136
  - lib/seeing_is_believing.rb
@@ -180,7 +152,6 @@ files:
180
152
  - lib/seeing_is_believing/debugger.rb
181
153
  - lib/seeing_is_believing/error.rb
182
154
  - lib/seeing_is_believing/evaluate_by_moving_files.rb
183
- - lib/seeing_is_believing/evaluate_with_eval_in.rb
184
155
  - lib/seeing_is_believing/event_stream/consumer.rb
185
156
  - lib/seeing_is_believing/event_stream/events.rb
186
157
  - lib/seeing_is_believing/event_stream/producer.rb
@@ -272,11 +243,11 @@ signing_key:
272
243
  specification_version: 4
273
244
  summary: Records results of every line of code in your file
274
245
  test_files:
246
+ - features/deprecated-flags.feature
275
247
  - features/errors.feature
276
248
  - features/examples.feature
277
249
  - features/flags.feature
278
250
  - features/regression.feature
279
- - features/safe.feature
280
251
  - features/support/env.rb
281
252
  - features/xmpfilter-style.feature
282
253
  - spec/binary/comment_formatter_spec.rb
@@ -1,33 +0,0 @@
1
- Feature: Running in safe-mode
2
-
3
- It would be nice to be able to expose SiB via a bot like hubot.
4
- To do this, though, you need to be able to trust the code that users submit.
5
- I wrote https://github.com/JoshCheek/eval_in to use the https://eval.in
6
- website to run code safely. SiB just needs to use it.
7
-
8
- @wip
9
- Scenario: Running normal code
10
- Given the file 'safe-example1.rb' 'print "hello, #{gets}"'
11
- And the stdin content "world"
12
- When I run "seeing_is_believing --safe safe-example1.rb"
13
- Then stderr is empty
14
- And the exit status is 0
15
- And stdout is:
16
- """
17
- print "hello, #{gets}" # => nil
18
-
19
- # >> hello, world
20
- """
21
-
22
- Scenario: Unsafe code
23
- Scenario: With --xmpfilter
24
- Scenario: With incompatible options
25
- Scenario: With --timeout
26
- Scenario: With --as
27
- Scenario: With --debug
28
- Scenario: Wpper-bound number of captures to prevent it from consuming too many resources
29
- --program program # Pass the program to execute as an argument
30
- --load-path dir # a dir that should be added to the $LOAD_PATH
31
- --require file # additional files to be required before running the program
32
- --encoding encoding # sets file encoding, equivalent to Ruby's -Kx (see `man ruby` for valid values)
33
- --shebang ruby-executable # if you want SiB to use some ruby other than the one in the path
@@ -1,27 +0,0 @@
1
- require 'eval_in'
2
- require 'stringio'
3
-
4
- class SeeingIsBelieving
5
- class EvaluateWithEvalIn
6
- def self.call(*args)
7
- new(*args).call
8
- end
9
-
10
- attr_accessor :program, :filename, :input_stream, :matrix_filename, :require_flags, :load_path_flags, :encoding, :timeout, :ruby_executable, :debugger
11
-
12
- def initialize(program, filename, options={})
13
- self.program = program
14
- # self.input_stream = options.fetch :input_stream, StringIO.new('')
15
- # self.timeout = options[:timeout]
16
- # self.debugger = options.fetch :debugger, Debugger.new(stream: nil)
17
- end
18
-
19
- def call
20
- eval_in_result = ::EvalIn.call(program, language: 'ruby/mri-2.1')
21
- result = Result.new
22
- EventStream::Consumer.new(StringIO.new eval_in_result.output)
23
- .each { |event| EventStream::UpdateResult.call result, event }
24
- result
25
- end
26
- end
27
- end