seeing_is_believing 3.3.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +39 -0
  3. data/{Readme.md → README.md} +9 -12
  4. data/Rakefile +12 -23
  5. data/appveyor.yml +3 -1
  6. data/features/flags.feature +251 -1
  7. data/features/regression.feature +166 -23
  8. data/features/xmpfilter-style.feature +1 -0
  9. data/lib/seeing_is_believing.rb +5 -2
  10. data/lib/seeing_is_believing/binary.rb +6 -1
  11. data/lib/seeing_is_believing/binary/annotate_end_of_file.rb +1 -1
  12. data/lib/seeing_is_believing/binary/annotate_marked_lines.rb +8 -5
  13. data/lib/seeing_is_believing/binary/comment_lines.rb +2 -2
  14. data/lib/seeing_is_believing/binary/commentable_lines.rb +7 -7
  15. data/lib/seeing_is_believing/binary/config.rb +21 -4
  16. data/lib/seeing_is_believing/binary/engine.rb +58 -1
  17. data/lib/seeing_is_believing/binary/format_comment.rb +9 -6
  18. data/lib/seeing_is_believing/binary/remove_annotations.rb +1 -1
  19. data/lib/seeing_is_believing/code.rb +5 -5
  20. data/lib/seeing_is_believing/compatibility.rb +28 -0
  21. data/lib/seeing_is_believing/evaluate_by_moving_files.rb +52 -71
  22. data/lib/seeing_is_believing/event_stream/consumer.rb +26 -28
  23. data/lib/seeing_is_believing/event_stream/events.rb +7 -0
  24. data/lib/seeing_is_believing/event_stream/handlers/record_exit_events.rb +3 -3
  25. data/lib/seeing_is_believing/event_stream/handlers/update_result.rb +2 -1
  26. data/lib/seeing_is_believing/event_stream/producer.rb +29 -5
  27. data/lib/seeing_is_believing/safe.rb +8 -7
  28. data/lib/seeing_is_believing/swap_files.rb +90 -0
  29. data/lib/seeing_is_believing/the_matrix.rb +17 -4
  30. data/lib/seeing_is_believing/version.rb +1 -1
  31. data/lib/seeing_is_believing/wrap_expressions.rb +27 -13
  32. data/lib/seeing_is_believing/wrap_expressions_with_inspect.rb +4 -1
  33. data/seeing_is_believing.gemspec +4 -6
  34. data/spec/binary/config_spec.rb +63 -35
  35. data/spec/binary/engine_spec.rb +11 -1
  36. data/spec/binary/format_comment_spec.rb +5 -1
  37. data/spec/evaluate_by_moving_files_spec.rb +35 -18
  38. data/spec/event_stream_spec.rb +15 -0
  39. data/spec/seeing_is_believing_spec.rb +148 -26
  40. data/spec/sib_spec_helpers/version.rb +17 -0
  41. data/spec/spec_helper.rb +2 -18
  42. data/spec/wrap_expressions_spec.rb +9 -2
  43. metadata +31 -31
  44. data/.travis.yml +0 -10
  45. data/lib/seeing_is_believing/customize_pp.rb +0 -5
  46. data/spec/binary/options_spec.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0c1356fef9747e418a57e2f151e4bc2f7625d6d8
4
- data.tar.gz: 27c33822870a7f0bf0f25172ed626d581b1b4906
2
+ SHA256:
3
+ metadata.gz: 138b4f2170848590bd310474298ed1c36861d74ae7e9e728d7d06343eaa2aa60
4
+ data.tar.gz: 98eeba43fe979029095e9efb5de96f33f405ec2729ffc80c5063f179aaaa6fd0
5
5
  SHA512:
6
- metadata.gz: b4ba3ac50ac5ac732c097e7dcffebdcd58c7345f8f40df8b1086b33c9d9ef69b5e030ebf139401edc57e89622475eeab1c0cf2a92b966bd0671c9bad6181e144
7
- data.tar.gz: 8bc5907b40214aa58377aec602033e08e47837239bed71d028e3833c4d9a75f28b59e88c55ec04f6c751e4a577695fb9175407b22340bfa3e41fcf7a5d8eb282
6
+ metadata.gz: 44f5ac4f46b544ed8ca22a8429aa85add4b45eb2626acd84b91f988c5d86f6ee6903791b2b5a876187ac4e8e998dd967f7c72585e842df86f513d29acbb0aae1
7
+ data.tar.gz: f3c96b87441107d7e5b9eef52c523a1bf8b13b20276cbcd00b1b9d4d1ec9781420b0f1c8aeb4cc40a245bb08051439c35770dcb65b8554b67b228a0db84b3115
@@ -0,0 +1,39 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Test
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.5', '2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Install binstubs (no rubygems / bundler at runtime, makes tests much much faster)
35
+ run: rake install
36
+ - name: Run rspec tests
37
+ run: rake spec
38
+ - name: Run cucumber features
39
+ run: rake cuke
@@ -1,5 +1,8 @@
1
- Unix/Mac: [![Unix Build Status](https://secure.travis-ci.org/JoshCheek/seeing_is_believing.svg?branch=master)](http://travis-ci.org/JoshCheek/seeing_is_believing)   
2
- Windows: [![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/JoshCheek/seeing_is_believing?branch=master&svg=true)](https://ci.appveyor.com/project/JoshCheek/seeing-is-believing)
1
+ https://github.com/JoshCheek/seeing_is_believing/workflows/Ruby/badge.svg
2
+
3
+ Unix/Mac: [![Unix Build Status](https://github.com/JoshCheek/seeing_is_believing/workflows/Test/badge.svg)](https://github.com/JoshCheek/seeing_is_believing/actions?query=workflow%3ATest)
4
+   
5
+ Appveyor: [![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/JoshCheek/seeing_is_believing?branch=master&svg=true)](https://ci.appveyor.com/project/JoshCheek/seeing-is-believing)
3
6
 
4
7
  Seeing Is Believing
5
8
  ===================
@@ -8,7 +11,7 @@ Evaluates Ruby code, recording the results of each line.
8
11
  Integrates with any extensible editor (I've integrated it with many already, see [the list](https://github.com/JoshCheek/seeing_is_believing/wiki/Editor-Integration)).
9
12
  If you like Swift Playgrounds, you'll like SiB.
10
13
 
11
- ![example](https://s3.amazonaws.com/josh.cheek/images/scratch/sib-example1.gif)
14
+ ![example](docs/example.gif)
12
15
 
13
16
 
14
17
  Helpful links
@@ -38,10 +41,6 @@ Known Issues
38
41
  ------------
39
42
 
40
43
  * Assumes utf-8 everywhere. If this is an issue, please see the [encodings](https://github.com/JoshCheek/seeing_is_believing/wiki/Encodings) section of the wiki.
41
- * `begin; else; break; end` this code (an else without a rescue) will emit a warning in Ruby, and is omitted from `Parser`'s AST.
42
- As such, I doubt that anyone will ever write it. But if you were to write it, it would blow up, because SiB rewrites your code, wrapping every expression that could have a value.
43
- This code will be wrapped. But using the value is **syntactically** invalid in Ruby, because it constitutes a "void value expression" (aka a pointless time sink and the cause of many bugs in SiB).
44
- Unfortunately, I can't easily check it to see if it's void since it's not in the parsed AST. But it's so edge that I don't think it's worth worrying about.
45
44
 
46
45
 
47
46
  Inspiration
@@ -53,12 +52,10 @@ Inspiration
53
52
 
54
53
 
55
54
  Shout outs
56
- ----------
55
+ -----------
56
+
57
+ * Whitequark for all the work on [Parser](http://github.com/whitequark/parser/)
57
58
 
58
- * Whitequark for all the work on [Parser](http://github.com/whitequark/parser/), which dramatically dramatically improved SiB (I used to have my own horribly shitty line-based parser)
59
- * [Travis CI](https://travis-ci.org/JoshCheek/seeing_is_believing)... I love you times a million! So many difficult bugs have been caught by this.
60
- It's so easy to work with, astoundingly convenient, helps me guarantee that SiB works on everyone else's computers, too. And it's free since SiB is open source.
61
- I literally have a Travis CI sticker on my laptop, I love you that much.
62
59
 
63
60
  License
64
61
  -------
data/Rakefile CHANGED
@@ -1,26 +1,13 @@
1
1
  desc 'Have Bundler setup a standalone environment -- run tests in this, b/c its faster and safer'
2
2
  task :install do
3
- exe_path = which("bundle")
4
- unless exe_path
5
- sh 'gem', 'install', 'bundler', '--no-ri', '--no-rdoc'
6
- end
7
-
8
- unless Dir.exist? 'bundle'
9
- # Running without rubygems # http://myronmars.to/n/dev-blog/2012/03/faster-test-boot-times-with-bundler-standalone
10
- sh 'bundle', 'install', '--standalone', '--binstubs', 'bundle/bin'
11
- end
3
+ # Running without rubygems http://myronmars.to/n/dev-blog/2012/03/faster-test-boot-times-with-bundler-standalone
4
+ which("bundle") or sh 'gem', 'install', 'bundler', '--no-ri', '--no-rdoc'
5
+ Dir.exist? 'bundle' or sh 'bundle', 'install', '--standalone', '--binstubs', 'bundle/bin'
12
6
  end
13
7
 
14
8
  desc 'Remove generated and irrelevant files'
15
9
  task :clean do
16
- rm_rf [
17
- 'bundle',
18
- '.bundle',
19
- 'Gemfile.lock',
20
- 'proving_grounds',
21
- 'tags',
22
- *Dir['*.gem'],
23
- ]
10
+ rm_rf %w[bundle .bundle Gemfile.lock proving_grounds tags] + Dir['*.gem']
24
11
  end
25
12
 
26
13
  directory 'bundle' do
@@ -30,11 +17,11 @@ end
30
17
 
31
18
  def require_paths
32
19
  require 'bundler'
33
- requrable_paths = Bundler.load.specs.flat_map { |spec|
34
- spec.require_paths.map do |path|
35
- File.join(spec.full_gem_path, path)
36
- end
37
- }.flat_map { |p| ['-I', p] }
20
+ Bundler.load.specs.flat_map do |spec|
21
+ spec.require_paths
22
+ .map { |path| File.join spec.full_gem_path, path }
23
+ .flat_map { |p| ['-I', p] }
24
+ end
38
25
  end
39
26
 
40
27
  desc 'Print the require paths for arbitrary binary execution'
@@ -55,6 +42,8 @@ task cuke: :bundle do
55
42
  sh 'ruby', '--disable-gem',
56
43
  *require_paths,
57
44
  '-S', 'bundle/bin/cucumber',
45
+ '--quiet', # omit stepdefs, which are usually spammy for me https://twitter.com/josh_cheek/status/1082767053071765504
46
+ '--fail-fast', # stop as soon as we see an error (don't waste CI time, don't make it hard to find error info later)
58
47
  '--tags', '~@not-implemented',
59
48
  '--tags', "~@not-#{RUBY_VERSION}",
60
49
  '--tags', "~@not-#{ruby_version_without_patchlevel}",
@@ -78,7 +67,7 @@ task default: [:spec, :cuke]
78
67
  desc 'Install dependencies and run tests (mainly for Travis CI)'
79
68
  task ci: [:spec, :cuke]
80
69
 
81
- def which(exe)
70
+ def self.which(exe)
82
71
  dirs = ENV["PATH"].split(File::PATH_SEPARATOR)
83
72
  exts = [""]
84
73
  exts.concat(ENV["PathExt"].to_s.split(File::PATH_SEPARATOR))
@@ -26,4 +26,6 @@ test_script:
26
26
 
27
27
  environment:
28
28
  matrix:
29
- - ruby_version: '21'
29
+ - ruby_version: '24'
30
+ - ruby_version: '25'
31
+ - ruby_version: '26'
@@ -268,7 +268,7 @@ Feature: Using flags
268
268
 
269
269
 
270
270
  Scenario: --alignment-strategy file
271
- Given the file "file_alignments.rb":
271
+ Given the file "file_alignments.rb":
272
272
  """
273
273
  # comment
274
274
  1
@@ -600,3 +600,253 @@ Feature: Using flags
600
600
  .to_s # => "0", "1", "2"
601
601
  end # => 3
602
602
  """
603
+
604
+
605
+ Scenario: --local-cwd causes the current working directory to be the same as the file
606
+ Given the file "subdir/cwd_of_file_test.rb" "__FILE__"
607
+ When I run "seeing_is_believing subdir/cwd_of_file_test.rb"
608
+ Then stderr is empty
609
+ And the exit status is 0
610
+ And stdout is '__FILE__ # => "subdir/cwd_of_file_test.rb"'
611
+ When I run "seeing_is_believing subdir/cwd_of_file_test.rb --local-cwd"
612
+ Then stderr is empty
613
+ And the exit status is 0
614
+ And stdout is '__FILE__ # => "cwd_of_file_test.rb"'
615
+
616
+
617
+ Scenario: --toggle-mark adds a mark to the line if it is unmarked and exists
618
+ Given the file "unmarked.rb":
619
+ """
620
+ 1
621
+ 2
622
+ """
623
+ When I run "seeing_is_believing unmarked.rb --toggle-mark 1"
624
+ Then stderr is empty
625
+ And the exit status is 0
626
+ And stdout is '{{"1 # => \n2"}}'
627
+ When I run "seeing_is_believing unmarked.rb --toggle-mark 2"
628
+ Then stderr is empty
629
+ And the exit status is 0
630
+ And stdout is '{{"1\n2 # => "}}'
631
+ When I run "seeing_is_believing unmarked.rb --toggle-mark 3"
632
+ Then stderr is empty
633
+ And the exit status is 0
634
+ And stdout is '{{"1\n2"}}'
635
+
636
+
637
+ Scenario: --toggle-mark doesn't add a mark to the line if it has a comment or can't be commented
638
+ Given the file "no_toggle_line_here.rb":
639
+ """
640
+ 1 # comment
641
+ "2
642
+ "
643
+ """
644
+ When I run "seeing_is_believing no_toggle_line_here.rb --toggle-mark 1"
645
+ Then stderr is empty
646
+ And the exit status is 0
647
+ And stdout is:
648
+ """
649
+ 1 # comment
650
+ "2
651
+ "
652
+ """
653
+ When I run "seeing_is_believing no_toggle_line_here.rb --toggle-mark 2"
654
+ Then stderr is empty
655
+ And the exit status is 0
656
+ And stdout is:
657
+ """
658
+ 1 # comment
659
+ "2
660
+ "
661
+ """
662
+ When I run "seeing_is_believing no_toggle_line_here.rb --toggle-mark 3"
663
+ Then stderr is empty
664
+ And the exit status is 0
665
+ And stdout is:
666
+ """
667
+ 1 # comment
668
+ "2
669
+ " # =>{{" "}}
670
+ """
671
+
672
+
673
+ Scenario: --toggle-mark removes a mark from the line if it is marked and exists
674
+ Given the file "marked.rb":
675
+ """
676
+ 1 # =>
677
+ 2 + 2 # =>
678
+ """
679
+ When I run "seeing_is_believing marked.rb --toggle-mark 1"
680
+ Then stderr is empty
681
+ And the exit status is 0
682
+ And stdout is '{{"1\n2 + 2 # => "}}'
683
+ When I run "seeing_is_believing marked.rb --toggle-mark 2"
684
+ Then stderr is empty
685
+ And the exit status is 0
686
+ And stdout is '{{"1 # => \n2 + 2"}}'
687
+ When I run "seeing_is_believing marked.rb --toggle-mark 3"
688
+ Then stderr is empty
689
+ And the exit status is 0
690
+ And stdout is '{{"1 # => \n2 + 2 # => "}}'
691
+
692
+
693
+ Scenario: --toggle-mark removes error lines, and stdout/stderr output
694
+ Given the file "output_to_toggle_off.rb":
695
+ """
696
+ 1 + "a" # ~> b
697
+ # >> c
698
+ # !> d
699
+ # ~> e
700
+ """
701
+ When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 1"
702
+ Then stdout is:
703
+ """
704
+ 1 + "a"
705
+ # >> c
706
+ # !> d
707
+ # ~> e
708
+ """
709
+ When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 2"
710
+ Then stdout is:
711
+ """
712
+ 1 + "a" # ~> b
713
+
714
+ # !> d
715
+ # ~> e
716
+ """
717
+ When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 3"
718
+ Then stdout is:
719
+ """
720
+ 1 + "a" # ~> b
721
+ # >> c
722
+
723
+ # ~> e
724
+ """
725
+ When I run "seeing_is_believing output_to_toggle_off.rb --toggle-mark 4"
726
+ Then stdout is:
727
+ """
728
+ 1 + "a" # ~> b
729
+ # >> c
730
+ # !> d
731
+ """
732
+
733
+
734
+ Scenario: --toggle-mark respects the --alignment-strategy of file and updates any existing annotations to respect it
735
+ Given the file "toggle_mark_with_file_alignment.rb":
736
+ """
737
+ 1
738
+
739
+ 1 + 1 # => 2
740
+ 1 + 1 + 1 # => 3
741
+ 1 + 1 + 1 + 1
742
+ """
743
+ When I run "seeing_is_believing --toggle-mark 1 --alignment-strategy file toggle_mark_with_file_alignment.rb"
744
+ Then stderr is empty
745
+ And the exit status is 0
746
+ And stdout is:
747
+ """
748
+ 1 # =>{{" "}}
749
+
750
+ 1 + 1 # => 2
751
+ 1 + 1 + 1 # => 3
752
+ 1 + 1 + 1 + 1
753
+ """
754
+ When I run "seeing_is_believing --toggle-mark 3 --alignment-strategy file toggle_mark_with_file_alignment.rb"
755
+ Then stderr is empty
756
+ And the exit status is 0
757
+ And stdout is:
758
+ """
759
+ 1
760
+
761
+ 1 + 1
762
+ 1 + 1 + 1 # => 3
763
+ 1 + 1 + 1 + 1
764
+ """
765
+
766
+
767
+ Scenario: --toggle-mark respects the --alignment-strategy of chunk and updates any existing annotations to respect it
768
+ Given the file "toggle_mark_with_chunk_alignments.rb":
769
+ """
770
+ 1+1# => 2
771
+ 1+1+1
772
+ 1+1+1+1
773
+
774
+ 1 + 1
775
+ # comment in the middle!
776
+ 1
777
+ """
778
+ When I run "seeing_is_believing --toggle-mark 2 --alignment-strategy chunk toggle_mark_with_chunk_alignments.rb"
779
+ Then stderr is empty
780
+ And the exit status is 0
781
+ And stdout is:
782
+ """
783
+ 1+1 # => 2
784
+ 1+1+1 # =>{{" "}}
785
+ 1+1+1+1
786
+
787
+ 1 + 1
788
+ # comment in the middle!
789
+ 1
790
+ """
791
+ When I run "seeing_is_believing --toggle-mark 5 --alignment-strategy chunk toggle_mark_with_chunk_alignments.rb"
792
+ Then stderr is empty
793
+ And the exit status is 0
794
+ And stdout is:
795
+ """
796
+ 1+1 # => 2
797
+ 1+1+1
798
+ 1+1+1+1
799
+
800
+ 1 + 1 # =>{{" "}}
801
+ # comment in the middle!
802
+ 1
803
+ """
804
+ When I run "seeing_is_believing --toggle-mark 1 --alignment-strategy chunk toggle_mark_with_chunk_alignments.rb"
805
+ Then stderr is empty
806
+ And the exit status is 0
807
+ And stdout is:
808
+ """
809
+ 1+1
810
+ 1+1+1
811
+ 1+1+1+1
812
+
813
+ 1 + 1
814
+ # comment in the middle!
815
+ 1
816
+ """
817
+
818
+
819
+ Scenario: --toggle-mark respects the --alignment-strategy of line and updates any existing annotations to respect it
820
+ Given the file "toggle_mark_with_line_alignments.rb":
821
+ """
822
+ 1
823
+ 1 + 1# => x
824
+ 1 + 1 + 1
825
+ """
826
+ When I run "seeing_is_believing --toggle-mark 1 --alignment-strategy line toggle_mark_with_line_alignments.rb"
827
+ Then stderr is empty
828
+ And the exit status is 0
829
+ And stdout is:
830
+ """
831
+ 1 # =>{{" "}}
832
+ 1 + 1 # => x
833
+ 1 + 1 + 1
834
+ """
835
+ When I run "seeing_is_believing --toggle-mark 2 --alignment-strategy line toggle_mark_with_line_alignments.rb"
836
+ Then stderr is empty
837
+ And the exit status is 0
838
+ And stdout is:
839
+ """
840
+ 1
841
+ 1 + 1
842
+ 1 + 1 + 1
843
+ """
844
+ When I run "seeing_is_believing --toggle-mark 3 --alignment-strategy line toggle_mark_with_line_alignments.rb"
845
+ Then stderr is empty
846
+ And the exit status is 0
847
+ And stdout is:
848
+ """
849
+ 1
850
+ 1 + 1 # => x
851
+ 1 + 1 + 1 # =>{{" "}}
852
+ """
@@ -267,6 +267,8 @@ Feature:
267
267
  """
268
268
 
269
269
 
270
+ # ChildProcess doesn't seem to handle this well in Windows. IDK.
271
+ @not-windows
270
272
  Scenario: Long DATA segment in a valid file
271
273
  Given the file "long_valid_data_segment.rb":
272
274
  """
@@ -434,6 +436,9 @@ Feature:
434
436
  """
435
437
 
436
438
 
439
+ # 2.4 and 2.5 don't correclty detect deadlock on Windows: https://bugs.ruby-lang.org/issues/16110
440
+ @not-2.4
441
+ @not-2.5
437
442
  Scenario: Deadlocked
438
443
  Given the file "deadlocked.rb":
439
444
  """
@@ -465,29 +470,6 @@ Feature:
465
470
  """
466
471
 
467
472
 
468
- # See this issue for the issue we're testing for: https://github.com/JoshCheek/seeing_is_believing/issues/46
469
- # See this issue for why we turn it off on 2.4: https://github.com/flori/json/issues/309
470
- #
471
- # Not going to get too detailed on what it prints, b/c that message seems pretty fragile,
472
- # but just generally that it doesn't fkn blow up
473
- @not-2.4
474
- Scenario: Old JSON bug
475
- Given the file "json_and_encodings.rb":
476
- """
477
- # encoding: utf-8
478
- require 'json'
479
- JSON.parse JSON.dump("√")
480
- """
481
- When I run "seeing_is_believing json_and_encodings.rb"
482
- Then stderr is empty
483
- And the exit status is 1
484
- And stdout includes:
485
- """
486
- require 'json' # => true
487
- JSON.parse JSON.dump("√")
488
- """
489
-
490
-
491
473
  # https://github.com/JoshCheek/seeing_is_believing/wiki/Encodings
492
474
  # https://github.com/JoshCheek/seeing_is_believing/issues/109
493
475
  Scenario: Assumes utf-8 for files regardless of what Ruby thinks
@@ -753,3 +735,164 @@ Feature:
753
735
  require 'seeing_is_believing' # => true
754
736
  SeeingIsBelieving.call("1+1").result[1][0] # => "2"
755
737
  """
738
+
739
+
740
+ Scenario: Errors should not blow away comments (Issue #120)
741
+ Given the file "sib_with_error_on_uncommented_line.rb" "dne"
742
+ And the file "sib_with_error_on_commented_line.rb" "dne # this doesn't exist!"
743
+ When I run "seeing_is_believing -x sib_with_error_on_uncommented_line.rb"
744
+ Then stdout is:
745
+ """
746
+ dne # ~> NameError: undefined local variable or method `dne' for main:Object
747
+
748
+ # ~> NameError
749
+ # ~> undefined local variable or method `dne' for main:Object
750
+ # ~>
751
+ # ~> sib_with_error_on_uncommented_line.rb:1:in `<main>'
752
+ """
753
+ When I run "seeing_is_believing -x sib_with_error_on_commented_line.rb"
754
+ Then stdout is:
755
+ """
756
+ dne # this doesn't exist!
757
+
758
+ # ~> NameError
759
+ # ~> undefined local variable or method `dne' for main:Object
760
+ # ~>
761
+ # ~> sib_with_error_on_commented_line.rb:1:in `<main>'
762
+ """
763
+ When I run "seeing_is_believing sib_with_error_on_uncommented_line.rb"
764
+ Then stdout is:
765
+ """
766
+ dne # ~> NameError: undefined local variable or method `dne' for main:Object
767
+
768
+ # ~> NameError
769
+ # ~> undefined local variable or method `dne' for main:Object
770
+ # ~>
771
+ # ~> sib_with_error_on_uncommented_line.rb:1:in `<main>'
772
+ """
773
+ When I run "seeing_is_believing sib_with_error_on_commented_line.rb"
774
+ Then stdout is:
775
+ """
776
+ dne # this doesn't exist!
777
+
778
+ # ~> NameError
779
+ # ~> undefined local variable or method `dne' for main:Object
780
+ # ~>
781
+ # ~> sib_with_error_on_commented_line.rb:1:in `<main>'
782
+ """
783
+
784
+
785
+ Scenario: Errors on files read from stdin with --local-cwd are matched to the correct lines
786
+ Given the file "local_cwd_and_error_on_uncommented_line.rb" "dne"
787
+ When I run "seeing_is_believing --local-cwd < local_cwd_and_error_on_uncommented_line.rb"
788
+ Then stdout includes "dne # ~> NameError: undefined local variable or method `dne' for main:Object"
789
+
790
+
791
+ Scenario: Inspects strings even when they have a singleton class (Issue #118)
792
+ Given the file "result_of_inspect_has_a_singleton_class.rb":
793
+ """
794
+ str = "a string"
795
+ def str.inspect
796
+ self
797
+ end
798
+ str # =>
799
+ """
800
+ When I run "seeing_is_believing -x result_of_inspect_has_a_singleton_class.rb"
801
+ Then stderr is empty
802
+ And the exit status is 0
803
+ And stdout is:
804
+ """
805
+ str = "a string"
806
+ def str.inspect
807
+ self
808
+ end
809
+ str # => a string
810
+ """
811
+
812
+
813
+ Scenario: The last line can end in a semicolon
814
+ When I run "seeing_is_believing -e '1'"
815
+ Then stdout is "1 # => 1"
816
+ When I run "seeing_is_believing -e '1;'"
817
+ Then stdout is "1; # => 1"
818
+
819
+
820
+ Scenario: A spy / proxy class (Issue #136)
821
+ Given the file "spy_class.rb":
822
+ """
823
+ class String
824
+ def self.===(obj)
825
+ true
826
+ end
827
+ end
828
+ class Spy < BasicObject
829
+ def method_missing(name, *args, &block)
830
+ self
831
+ end
832
+ end
833
+ Spy.new # =>
834
+ """
835
+ When I run "seeing_is_believing -x spy_class.rb"
836
+ Then stderr is empty
837
+ And the exit status is 0
838
+ And stdout includes "Spy.new # => #<Spy:"
839
+
840
+
841
+ Scenario: Refined inspect
842
+ Given the file "refined_inspect.rb":
843
+ """
844
+ module Humanize
845
+ refine Float do
846
+ def inspect
847
+ rounded = "%.2f" % self
848
+ rounded.reverse!
849
+ rounded.gsub! /(\d{3})/, '\1,'
850
+ rounded.chomp! ","
851
+ rounded.reverse!
852
+ rounded
853
+ end #
854
+ end
855
+ end
856
+ using Humanize
857
+ 12345.6789 # =>
858
+ """
859
+ When I run "seeing_is_believing refined_inspect.rb"
860
+ Then stderr is empty
861
+ And the exit status is 0
862
+ And stdout is:
863
+ """
864
+ module Humanize
865
+ refine Float do
866
+ def inspect
867
+ rounded = "%.2f" % self # => "12345.68"
868
+ rounded.reverse! # => "86.54321"
869
+ rounded.gsub! /(\d{3})/, '\1,' # => "86.543,21"
870
+ rounded.chomp! "," # => nil
871
+ rounded.reverse! # => "12,345.68"
872
+ rounded # => "12,345.68"
873
+ end #
874
+ end # => #<refinement:Float@Humanize>
875
+ end # => #<refinement:Float@Humanize>
876
+ using Humanize # => main
877
+ 12345.6789 # => 12,345.68
878
+ """
879
+ When I run "seeing_is_believing refined_inspect.rb -x"
880
+ Then stderr is empty
881
+ And the exit status is 0
882
+ Then stdout is:
883
+ """
884
+ module Humanize
885
+ refine Float do
886
+ def inspect
887
+ rounded = "%.2f" % self
888
+ rounded.reverse!
889
+ rounded.gsub! /(\d{3})/, '\1,'
890
+ rounded.chomp! ","
891
+ rounded.reverse!
892
+ rounded
893
+ end #
894
+ end
895
+ end
896
+ using Humanize
897
+ 12345.6789 # => 12,345.68
898
+ """