|
2 | 2 | require 'coverage'
|
3 | 3 |
|
4 | 4 | describe 'Coverage.start' do
|
| 5 | + before :each do |
| 6 | + Coverage.should_not.running? |
| 7 | + end |
| 8 | + |
| 9 | + after :each do |
| 10 | + Coverage.result(stop: true, clear: true) if Coverage.running? |
| 11 | + end |
| 12 | + |
| 13 | + it "enables the coverage measurement" do |
| 14 | + Coverage.start |
| 15 | + Coverage.should.running? |
| 16 | + end |
| 17 | + |
| 18 | + it "returns nil" do |
| 19 | + Coverage.start.should == nil |
| 20 | + end |
| 21 | + |
5 | 22 | ruby_version_is '3.2' do
|
6 |
| - it "can measure coverage within eval" do |
| 23 | + it "accepts :all optional argument" do |
| 24 | + Coverage.start(:all) |
| 25 | + Coverage.should.running? |
| 26 | + end |
| 27 | + |
| 28 | + it "accepts lines: optional keyword argument" do |
| 29 | + Coverage.start(lines: true) |
| 30 | + Coverage.should.running? |
| 31 | + end |
| 32 | + |
| 33 | + it "accepts branches: optional keyword argument" do |
| 34 | + Coverage.start(branches: true) |
| 35 | + Coverage.should.running? |
| 36 | + end |
| 37 | + |
| 38 | + it "accepts methods: optional keyword argument" do |
| 39 | + Coverage.start(methods: true) |
| 40 | + Coverage.should.running? |
| 41 | + end |
| 42 | + |
| 43 | + it "accepts eval: optional keyword argument" do |
| 44 | + Coverage.start(eval: true) |
| 45 | + Coverage.should.running? |
| 46 | + end |
| 47 | + |
| 48 | + it "accepts oneshot_lines: optional keyword argument" do |
| 49 | + Coverage.start(oneshot_lines: true) |
| 50 | + Coverage.should.running? |
| 51 | + end |
| 52 | + |
| 53 | + it "ignores unknown keyword arguments" do |
| 54 | + Coverage.start(foo: true) |
| 55 | + Coverage.should.running? |
| 56 | + end |
| 57 | + |
| 58 | + it "expects a Hash if not passed :all" do |
| 59 | + -> { |
| 60 | + Coverage.start(42) |
| 61 | + }.should raise_error(TypeError, "no implicit conversion of Integer into Hash") |
| 62 | + end |
| 63 | + |
| 64 | + it "does not accept both lines: and oneshot_lines: keyword arguments" do |
| 65 | + -> { |
| 66 | + Coverage.start(lines: true, oneshot_lines: true) |
| 67 | + }.should raise_error(RuntimeError, "cannot enable lines and oneshot_lines simultaneously") |
| 68 | + end |
| 69 | + |
| 70 | + it "enables the coverage measurement if passed options with `false` value" do |
| 71 | + Coverage.start(lines: false, branches: false, methods: false, eval: false, oneshot_lines: false) |
| 72 | + Coverage.should.running? |
| 73 | + end |
| 74 | + |
| 75 | + it "measures coverage within eval" do |
7 | 76 | Coverage.start(lines: true, eval: true)
|
8 | 77 | eval("Object.new\n"*3, binding, "test.rb", 1)
|
9 | 78 | Coverage.result["test.rb"].should == {lines: [1, 1, 1]}
|
|
0 commit comments