mutiny 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +18 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +6 -0
  7. data/Gemfile +5 -0
  8. data/Gemfile.lock +113 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +16 -0
  11. data/RELEASES.md +8 -0
  12. data/Rakefile +23 -0
  13. data/TODO.md +55 -0
  14. data/bin/mutiny +35 -0
  15. data/examples/buggy_calculator/.rspec +2 -0
  16. data/examples/buggy_calculator/lib/calculator/max.rb +9 -0
  17. data/examples/buggy_calculator/lib/calculator.rb +4 -0
  18. data/examples/buggy_calculator/spec/calculator/max_spec.rb +17 -0
  19. data/examples/buggy_calculator/spec/spec_helper.rb +89 -0
  20. data/examples/calculator/.rspec +2 -0
  21. data/examples/calculator/lib/calculator/max.rb +9 -0
  22. data/examples/calculator/lib/calculator/min.rb +9 -0
  23. data/examples/calculator/lib/calculator.rb +5 -0
  24. data/examples/calculator/spec/calculator/max_spec.rb +17 -0
  25. data/examples/calculator/spec/calculator/min_spec.rb +17 -0
  26. data/examples/calculator/spec/spec_helper.rb +89 -0
  27. data/examples/untested_calculator/.rspec +2 -0
  28. data/examples/untested_calculator/lib/calculator/max.rb +9 -0
  29. data/examples/untested_calculator/lib/calculator.rb +4 -0
  30. data/examples/untested_calculator/spec/spec_helper.rb +89 -0
  31. data/lib/mutiny/configuration.rb +25 -0
  32. data/lib/mutiny/integration/rspec/context.rb +26 -0
  33. data/lib/mutiny/integration/rspec/parser.rb +36 -0
  34. data/lib/mutiny/integration/rspec/runner.rb +58 -0
  35. data/lib/mutiny/integration/rspec/test.rb +16 -0
  36. data/lib/mutiny/integration/rspec/test_set.rb +17 -0
  37. data/lib/mutiny/integration/rspec.rb +25 -0
  38. data/lib/mutiny/mode/check.rb +62 -0
  39. data/lib/mutiny/mode/mutate.rb +29 -0
  40. data/lib/mutiny/mode.rb +19 -0
  41. data/lib/mutiny/mutants/mutant.rb +32 -0
  42. data/lib/mutiny/mutants/mutant_set.rb +42 -0
  43. data/lib/mutiny/mutants/mutation/method/binary_arithmetic_operator_replacement.rb +15 -0
  44. data/lib/mutiny/mutants/mutation/method/conditional_operator_deletion.rb +19 -0
  45. data/lib/mutiny/mutants/mutation/method/conditional_operator_insertion.rb +25 -0
  46. data/lib/mutiny/mutants/mutation/method/conditional_operator_replacement.rb +19 -0
  47. data/lib/mutiny/mutants/mutation/method/helpers/infix_operator_replacement.rb +17 -0
  48. data/lib/mutiny/mutants/mutation/method/helpers/operator_replacement.rb +81 -0
  49. data/lib/mutiny/mutants/mutation/method/logical_operator_deletion.rb +19 -0
  50. data/lib/mutiny/mutants/mutation/method/logical_operator_insertion.rb +24 -0
  51. data/lib/mutiny/mutants/mutation/method/logical_operator_replacement.rb +15 -0
  52. data/lib/mutiny/mutants/mutation/method/relational_expression_replacement.rb +19 -0
  53. data/lib/mutiny/mutants/mutation/method/relational_operator_replacement.rb +15 -0
  54. data/lib/mutiny/mutants/mutation/method/shortcut_assignment_operator_replacement.rb +23 -0
  55. data/lib/mutiny/mutants/mutation/method/unary_arithmetic_operator_deletion.rb +29 -0
  56. data/lib/mutiny/mutants/mutation/method/unary_arithmetic_operator_insertion.rb +29 -0
  57. data/lib/mutiny/mutants/mutation.rb +10 -0
  58. data/lib/mutiny/mutants/mutation_set.rb +24 -0
  59. data/lib/mutiny/mutants/ruby.rb +42 -0
  60. data/lib/mutiny/pattern.rb +17 -0
  61. data/lib/mutiny/reporter/stdout.rb +9 -0
  62. data/lib/mutiny/subjects/environment/type.rb +54 -0
  63. data/lib/mutiny/subjects/environment.rb +25 -0
  64. data/lib/mutiny/subjects/subject.rb +32 -0
  65. data/lib/mutiny/subjects/subject_set.rb +17 -0
  66. data/lib/mutiny/subjects.rb +3 -0
  67. data/lib/mutiny/tests/test.rb +12 -0
  68. data/lib/mutiny/tests/test_run.rb +18 -0
  69. data/lib/mutiny/tests/test_set.rb +44 -0
  70. data/lib/mutiny/tests.rb +3 -0
  71. data/lib/mutiny/version.rb +3 -0
  72. data/lib/mutiny.rb +4 -0
  73. data/mutiny.gemspec +32 -0
  74. data/spec/integration/check_spec.rb +39 -0
  75. data/spec/integration/mutate_spec.rb +35 -0
  76. data/spec/spec_helper.rb +38 -0
  77. data/spec/support/aruba.rb +12 -0
  78. data/spec/support/in_example_project.rb +17 -0
  79. data/spec/support/shared_examples/shared_examples_for_an_operator_replacement_mutation.rb +26 -0
  80. data/spec/unit/integration/rspec/parser_spec.rb +23 -0
  81. data/spec/unit/integration/rspec/runner_spec.rb +47 -0
  82. data/spec/unit/mutants/mutant_set_spec.rb +57 -0
  83. data/spec/unit/mutants/mutations/method/binary_operator_replacement_spec.rb +11 -0
  84. data/spec/unit/mutants/mutations/method/conditional_operator_deletion_spec.rb +17 -0
  85. data/spec/unit/mutants/mutations/method/conditional_operator_insertion_spec.rb +17 -0
  86. data/spec/unit/mutants/mutations/method/conditional_operator_replacement_spec.rb +16 -0
  87. data/spec/unit/mutants/mutations/method/logical_operator_deletion_spec.rb +17 -0
  88. data/spec/unit/mutants/mutations/method/logical_operator_insertion_spec.rb +17 -0
  89. data/spec/unit/mutants/mutations/method/logical_operator_replacement_spec.rb +11 -0
  90. data/spec/unit/mutants/mutations/method/relational_expression_replacement_spec.rb +18 -0
  91. data/spec/unit/mutants/mutations/method/relational_operator_replacement_spec.rb +11 -0
  92. data/spec/unit/mutants/mutations/method/shortcut_assignment_operator_replacement_spec.rb +12 -0
  93. data/spec/unit/mutants/mutations/method/unary_arithmetic_operator_deletion_spec.rb +21 -0
  94. data/spec/unit/mutants/mutations/method/unary_arithmetic_operator_insertion_spec.rb +21 -0
  95. data/spec/unit/pattern_spec.rb +28 -0
  96. data/spec/unit/subjects/environment/type_spec.rb +54 -0
  97. data/spec/unit/subjects/environment_spec.rb +71 -0
  98. data/spec/unit/subjects/subject_spec.rb +25 -0
  99. data/spec/unit/subjects/test_set_spec.rb +75 -0
  100. metadata +310 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b0cd4975a5e102b5494dea373d982f29a4360b1
4
+ data.tar.gz: 84b81be52e16ec0438d308f8b41638a664c7d939
5
+ SHA512:
6
+ metadata.gz: b63df8d72301fbce3ac705294ef4821fc51f076681518b2ba7b4b0936de19a30e5a09c3890464780e6b175c9ad4b9771c4dd74f4afc9a2967a1edcf0a1dff3c3
7
+ data.tar.gz: 65204290c1816ab66893e05469c9425b4fc8b7d10658dc90c32b0d079e04f3f416339ced292fc18eb855910fdbabb75147cc3c9ff9c1c81502917cd232fcd0d7
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ /.bundle
2
+ .DS_Store
3
+ coverage
4
+ .tmp
5
+ .mutants
6
+ pkg
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ Include:
3
+ - Gemfile
4
+ - Rakefile
5
+ Exclude:
6
+ - vendor/*
7
+
8
+ StringLiterals:
9
+ Enabled: false
10
+
11
+ LineLength:
12
+ Max: 99
13
+
14
+ Documentation:
15
+ Enabled: false
16
+
17
+ Style/TrivialAccessors:
18
+ ExactNameMatch: true
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ addons:
5
+ code_climate:
6
+ repo_token: 0297c93e8cb012ae60aa0760b795608f96c681e1493d98153d5cd7bd97e3b650
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ ruby "2.2.2"
2
+ source "https://rubygems.org"
3
+
4
+ # Specify your gem's dependencies in mutiny.gemspec
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,113 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mutiny (0.1.0)
5
+ gli (~> 2.13.0)
6
+ metamorpher (~> 0.2.2)
7
+ parser (~> 2.2.2)
8
+ unparser (~> 0.2.4)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ abstract_type (0.0.7)
14
+ adamantium (0.2.0)
15
+ ice_nine (~> 0.11.0)
16
+ memoizable (~> 0.4.0)
17
+ aruba (0.6.2)
18
+ childprocess (>= 0.3.6)
19
+ cucumber (>= 1.1.1)
20
+ rspec-expectations (>= 2.7.0)
21
+ ast (2.0.0)
22
+ astrolabe (1.3.0)
23
+ parser (>= 2.2.0.pre.3, < 3.0)
24
+ attributable (0.1.0)
25
+ builder (3.2.2)
26
+ childprocess (0.5.6)
27
+ ffi (~> 1.0, >= 1.0.11)
28
+ codeclimate-test-reporter (0.4.7)
29
+ simplecov (>= 0.7.1, < 1.0.0)
30
+ concord (0.1.5)
31
+ adamantium (~> 0.2.0)
32
+ equalizer (~> 0.0.9)
33
+ cucumber (2.0.0)
34
+ builder (>= 2.1.2)
35
+ cucumber-core (~> 1.1.3)
36
+ diff-lcs (>= 1.1.3)
37
+ gherkin (~> 2.12)
38
+ multi_json (>= 1.7.5, < 2.0)
39
+ multi_test (>= 0.1.2)
40
+ cucumber-core (1.1.3)
41
+ gherkin (~> 2.12.0)
42
+ diff-lcs (1.2.5)
43
+ docile (1.1.5)
44
+ equalizer (0.0.11)
45
+ ffi (1.9.8)
46
+ gherkin (2.12.2)
47
+ multi_json (~> 1.3)
48
+ gli (2.13.1)
49
+ ice_nine (0.11.1)
50
+ json (1.8.2)
51
+ memoizable (0.4.2)
52
+ thread_safe (~> 0.3, >= 0.3.1)
53
+ metamorpher (0.2.2)
54
+ attributable (~> 0.1.0)
55
+ parser (~> 2.2.2)
56
+ unparser (~> 0.2.4)
57
+ multi_json (1.11.0)
58
+ multi_test (0.1.2)
59
+ parser (2.2.2.5)
60
+ ast (>= 1.1, < 3.0)
61
+ powerpack (0.1.1)
62
+ procto (0.0.2)
63
+ rainbow (2.0.0)
64
+ rake (10.4.2)
65
+ rspec (3.2.0)
66
+ rspec-core (~> 3.2.0)
67
+ rspec-expectations (~> 3.2.0)
68
+ rspec-mocks (~> 3.2.0)
69
+ rspec-core (3.2.3)
70
+ rspec-support (~> 3.2.0)
71
+ rspec-expectations (3.2.1)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.2.0)
74
+ rspec-mocks (3.2.1)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.2.0)
77
+ rspec-support (3.2.2)
78
+ rubocop (0.31.0)
79
+ astrolabe (~> 1.3)
80
+ parser (>= 2.2.2.1, < 3.0)
81
+ powerpack (~> 0.1)
82
+ rainbow (>= 1.99.1, < 3.0)
83
+ ruby-progressbar (~> 1.4)
84
+ ruby-progressbar (1.7.5)
85
+ simplecov (0.10.0)
86
+ docile (~> 1.1.0)
87
+ json (~> 1.8)
88
+ simplecov-html (~> 0.10.0)
89
+ simplecov-html (0.10.0)
90
+ thread_safe (0.3.5)
91
+ unparser (0.2.4)
92
+ abstract_type (~> 0.0.7)
93
+ adamantium (~> 0.2.0)
94
+ concord (~> 0.1.5)
95
+ diff-lcs (~> 1.2.5)
96
+ equalizer (~> 0.0.9)
97
+ parser (~> 2.2.2)
98
+ procto (~> 0.0.2)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ aruba (~> 0.6.0)
105
+ bundler (~> 1.10.2)
106
+ codeclimate-test-reporter (~> 0.4.6)
107
+ mutiny!
108
+ rake (~> 10.4.2)
109
+ rspec (~> 3.2.0)
110
+ rubocop (~> 0.31.0)
111
+
112
+ BUNDLED WITH
113
+ 1.10.2
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Louis Rose
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Mutiny [![Build Status](https://travis-ci.org/mutiny/mutiny.svg?branch=master)](https://travis-ci.org/mutiny/mutiny) [![Code Climate](https://codeclimate.com/github/mutiny/mutiny/badges/gpa.svg)](https://codeclimate.com/github/mutiny/mutiny) [![Dependency Status](https://gemnasium.com/mutiny/mutiny.svg)](https://gemnasium.com/mutiny/mutiny) [![Test Coverage](https://codeclimate.com/github/mutiny/mutiny/badges/coverage.svg)](https://codeclimate.com/github/mutiny/mutiny)
2
+
3
+ A tiny mutation testing framework for Ruby. Used for exploring research ideas. For more stable and complete mutation testing in Ruby, use [mutant](https://github.com/mbj/mutant).
4
+
5
+ Currently supports Ruby versions of these [method level mutation operators](http://cs.gmu.edu/~offutt/mujava/mutopsMethod.pdf).
6
+
7
+ #### Usage
8
+ * `git clone` this repo
9
+ * `bundle install`
10
+ * `./bin/mutiny ./examples/max.rb ./examples/max_tests.rb` Note that we currently assume that tests.rb is a line-separated set of predicates (expressions that evaluate to either true or false).
11
+
12
+ ## Acknowledgments
13
+
14
+ Thank-you to the authors of other projects and resources that have inspired mutiny, including:
15
+
16
+ * Markus Schirp's [mutant](https://github.com/mbj/mutant), which paved the way for modern mutation testing in Ruby. In particular, mutiny's RSpec integration is based on the Markus's stellar work on mutant.
data/RELEASES.md ADDED
@@ -0,0 +1,8 @@
1
+ # Release History
2
+
3
+ ## v0.1.0 (5 June 2015)
4
+ Provide support for:
5
+ * Running mutation testing commands via the `mutiny` binary
6
+ * Checking that a program is amenable to mutation testing
7
+ * Generating mutants using traditional method-level operators
8
+ * Integration with RSpec 3
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task default: ["test:unit", "test:integration", "style:check"]
5
+
6
+ namespace :test do
7
+ RSpec::Core::RakeTask.new(:unit) do |task|
8
+ task.pattern = "./spec/unit{,/*/**}/*_spec.rb"
9
+ end
10
+
11
+ RSpec::Core::RakeTask.new(:integration) do |task|
12
+ task.pattern = "./spec/integration{,/*/**}/*_spec.rb"
13
+ end
14
+ end
15
+
16
+ namespace :style do
17
+ require "rubocop/rake_task"
18
+
19
+ desc "Run RuboCop on the lib directory"
20
+ RuboCop::RakeTask.new(:check) do |task|
21
+ task.options = ["--auto-correct"]
22
+ end
23
+ end
data/TODO.md ADDED
@@ -0,0 +1,55 @@
1
+ ### TODO
2
+
3
+ ### New implementation
4
+
5
+ * Reorganise lib, having in mind a "mutiny-core" which is separate to specific integrations (RSpec, etc), specific mutators (Metamorpher-based, etc), specific reporters (command-line, HTML, etc), etc
6
+
7
+ #### Analysis mode
8
+ * Should calculate mutation score
9
+ * Need to figure out approach for running tests on a mutant
10
+
11
+ ### Original implementation
12
+
13
+ * Experimentation to validate approach
14
+ * Write scripting
15
+ * Incremental: Should generate mutant delta (new / deleted mutants) between two git commits. Creating new mutants should be possible from existing change detector. Deleting obsoleted mutants will likely require enhancements to the change detector.
16
+ * Experimental harness: should run non-incremental mode for each commit, and compare to results of incremental mode. Store data for paper and print a summary that shows the number of mutants evaluated by incremental and non-incremental mode.
17
+
18
+ * Candidate projects
19
+ * Thor: https://github.com/erikhuda/thor
20
+ * Rake (ruled out as it uses minitest rather than RSpec)
21
+ * Rack (ruled out as it uses Bacon rather than RSpec)
22
+ * ActiveSupport and other Rails subgems (ruled out as it uses minitest rather than RSpec)
23
+
24
+ * Experiments
25
+ * Compare incremental and non-incremental mutator (seeding of faults) to determine typical magnitude of change over a project. What kind of granularity do we need to make a significant difference (file < method < ast nodes)?
26
+ * Compare incremental and non-incremental analyser to determine typical impact of change on mutation testing. Analyser will first need to be enhanced with an incremental model that determines which of a set of existing mutants need to be reevaluated.
27
+
28
+ * Overall aim: investigate the time savings of using incremental mode over the course of the project's history
29
+ * Measurements
30
+ * Could compare time taken for mutation testing each commit.
31
+ * Alternatively, could compare the number of mutants that need to be re-evaluated. This would allow experimentation to proceed without actually executing any tests; just creating mutants and marking those which need to be re-evaluated. The incremental mode should count any new mutants, mark any mutants from the previous round that need to be re-evaluated, (and mark any mutants from the previous round that need to be deleted?).
32
+ * Validity of results:
33
+ * Whatever is measured, I need to compare the _results_ of incremental and non-incremental modes to ensure that incremental mode is correct.
34
+ * Might need to enhance the change detector to be able to identify dependencies of units. For example, if `max_spec` tests `max` and `max` uses `calculator`, `max_spec` is dependent on calculator. If `calculator` changes, `max_spec` should be detected as impacted.
35
+
36
+ * Try new approach to specifying mutation operators, particularly if this makes incremental mutation testing easier.
37
+ * Add a Rewrite class to Ast module which can build and apply rewritings based on syntax in comments
38
+ * Add notions of MutationOperator that are specified with single rewrite, and with several rewrites.
39
+
40
+ * More fine-grained change detection. Some ideas:
41
+ * When an example is removed from a spec, we should be able to quickly recompute the mutation score. To allow this, we would need to store the results of each example for each mutant. We then remove the results for the deleted example, and recalculate the mutation score without running any tests.
42
+
43
+ * When a change to a unit is equivalent to swapping the unit for a previously analysed mutant of that unit, we should be able to quickly recompute the mutation score. We simply swap the mutant and unit in the results, and recalculate whether mutants are alive or dead (the new unit might cause different mutants to die). Again, to allow this we would need to store the results of each example for each mutant.
44
+
45
+ * When a change to a unit is localised to a single line / method / subset of the file (i.e., a fragment), we only need to recalculate the mutants for that fragment. (However, I suspect we will often need to re-test the mutants and source file to obtain an accurate mutation score: i.e., unlike the points above, this speed up only impacts mutant creation and not mutant analysis) To allow this, the mutation creation component should be able to locate mutation sites in a specific fragment of a file.
46
+
47
+ * Housekeeping
48
+
49
+ * Consider refactoring mutant.rb so that it does not contain a code attribute (perhaps instead it should compute code by passing the file and line number to its operator?)
50
+
51
+ * Should the change detector be a separate component, or should it be part of the core?
52
+
53
+ * Tests for Session.
54
+
55
+ * Extend framework to explore Program Analyser and more sophisticated Test Case Provider components (see OmniGraffle diagram)
data/bin/mutiny ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ require "gli"
3
+ require "mutiny"
4
+
5
+ include GLI::App
6
+
7
+ program_desc "A tiny mutation testing framework"
8
+
9
+ flag [:l, :loads], type: Array, default_value: ['lib']
10
+ flag [:r, :requires], type: Array, default_value: [File.basename(Dir.pwd)]
11
+ flag [:p, :patterns], type: Array, default_value: ['*']
12
+
13
+ pre do |global_options|
14
+ relevant_options = global_options.select { |k| %i(loads requires patterns).include?(k) }
15
+ @configuration = Mutiny::Configuration.new(relevant_options)
16
+ end
17
+
18
+ desc 'Check whether your project can be used with Mutiny'
19
+ long_desc 'Checks that Mutiny can load the modules and classes you specify,
20
+ and execute test cases for each module and class'
21
+ command :check do |c|
22
+ c.action do
23
+ Mutiny::Mode::Check.new(@configuration).run
24
+ end
25
+ end
26
+
27
+ desc 'Generate a set of mutants for your project'
28
+ long_desc 'Generates a set of mutants for your project and writes them to the .mutant directory'
29
+ command :mutate do |c|
30
+ c.action do
31
+ Mutiny::Mode::Mutate.new(@configuration).run
32
+ end
33
+ end
34
+
35
+ exit run(ARGV)
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,9 @@
1
+ module Calculator
2
+ class Max
3
+ def run(left, right)
4
+ max = left
5
+ max = right if right < left
6
+ max
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ require_relative "calculator/max"
2
+
3
+ module Calculator
4
+ end
@@ -0,0 +1,17 @@
1
+ require "calculator/max"
2
+
3
+ module Calculator
4
+ describe Max do
5
+ it "returns correct answer for a tie" do
6
+ expect(subject.run(4, 4)).to eq(4)
7
+ end
8
+
9
+ it "returns correct answer when first is larger" do
10
+ expect(subject.run(4, 3)).to eq(4)
11
+ end
12
+
13
+ it "returns correct answer when last is larger" do
14
+ expect(subject.run(3, 4)).to eq(4)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,89 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ # # These two settings work together to allow you to limit a spec run
46
+ # # to individual examples or groups you care about by tagging them with
47
+ # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
48
+ # # get run.
49
+ # config.filter_run :focus
50
+ # config.run_all_when_everything_filtered = true
51
+ #
52
+ # # Limits the available syntax to the non-monkey patched syntax that is
53
+ # # recommended. For more details, see:
54
+ # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
55
+ # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
56
+ # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
57
+ # config.disable_monkey_patching!
58
+ #
59
+ # # This setting enables warnings. It's recommended, but in some cases may
60
+ # # be too noisy due to issues in dependencies.
61
+ # config.warnings = true
62
+ #
63
+ # # Many RSpec users commonly either run the entire suite or an individual
64
+ # # file, and it's useful to allow more verbose output when running an
65
+ # # individual spec file.
66
+ # if config.files_to_run.one?
67
+ # # Use the documentation formatter for detailed output,
68
+ # # unless a formatter has already been configured
69
+ # # (e.g. via a command-line flag).
70
+ # config.default_formatter = 'doc'
71
+ # end
72
+ #
73
+ # # Print the 10 slowest examples and example groups at the
74
+ # # end of the spec run, to help surface which specs are running
75
+ # # particularly slow.
76
+ # config.profile_examples = 10
77
+ #
78
+ # # Run specs in random order to surface order dependencies. If you find an
79
+ # # order dependency and want to debug it, you can fix the order by providing
80
+ # # the seed, which is printed after each run.
81
+ # # --seed 1234
82
+ # config.order = :random
83
+ #
84
+ # # Seed global randomization in this process using the `--seed` CLI option.
85
+ # # Setting this allows you to use `--seed` to deterministically reproduce
86
+ # # test failures related to randomization by passing the same `--seed` value
87
+ # # as the one that triggered the failure.
88
+ # Kernel.srand config.seed
89
+ end
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,9 @@
1
+ module Calculator
2
+ class Max
3
+ def run(left, right)
4
+ max = left
5
+ max = right if right > left
6
+ max
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Calculator
2
+ class Min
3
+ def run(left, right)
4
+ max = left
5
+ max = right if right < left
6
+ max
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ require_relative "calculator/max"
2
+ require_relative "calculator/min"
3
+
4
+ module Calculator
5
+ end
@@ -0,0 +1,17 @@
1
+ require "calculator/max"
2
+
3
+ module Calculator
4
+ describe Max do
5
+ it "returns correct answer for a tie" do
6
+ expect(subject.run(4, 4)).to eq(4)
7
+ end
8
+
9
+ it "returns correct answer when first is larger" do
10
+ expect(subject.run(4, 3)).to eq(4)
11
+ end
12
+
13
+ it "returns correct answer when last is larger" do
14
+ expect(subject.run(3, 4)).to eq(4)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require "calculator/min"
2
+
3
+ module Calculator
4
+ describe Min do
5
+ it "returns correct answer for a tie" do
6
+ expect(subject.run(4, 4)).to eq(4)
7
+ end
8
+
9
+ it "returns correct answer when first is smaller" do
10
+ expect(subject.run(3, 4)).to eq(3)
11
+ end
12
+
13
+ it "returns correct answer when last is smaller" do
14
+ expect(subject.run(4, 3)).to eq(3)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,89 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ # # These two settings work together to allow you to limit a spec run
46
+ # # to individual examples or groups you care about by tagging them with
47
+ # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
48
+ # # get run.
49
+ # config.filter_run :focus
50
+ # config.run_all_when_everything_filtered = true
51
+ #
52
+ # # Limits the available syntax to the non-monkey patched syntax that is
53
+ # # recommended. For more details, see:
54
+ # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
55
+ # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
56
+ # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
57
+ # config.disable_monkey_patching!
58
+ #
59
+ # # This setting enables warnings. It's recommended, but in some cases may
60
+ # # be too noisy due to issues in dependencies.
61
+ # config.warnings = true
62
+ #
63
+ # # Many RSpec users commonly either run the entire suite or an individual
64
+ # # file, and it's useful to allow more verbose output when running an
65
+ # # individual spec file.
66
+ # if config.files_to_run.one?
67
+ # # Use the documentation formatter for detailed output,
68
+ # # unless a formatter has already been configured
69
+ # # (e.g. via a command-line flag).
70
+ # config.default_formatter = 'doc'
71
+ # end
72
+ #
73
+ # # Print the 10 slowest examples and example groups at the
74
+ # # end of the spec run, to help surface which specs are running
75
+ # # particularly slow.
76
+ # config.profile_examples = 10
77
+ #
78
+ # # Run specs in random order to surface order dependencies. If you find an
79
+ # # order dependency and want to debug it, you can fix the order by providing
80
+ # # the seed, which is printed after each run.
81
+ # # --seed 1234
82
+ # config.order = :random
83
+ #
84
+ # # Seed global randomization in this process using the `--seed` CLI option.
85
+ # # Setting this allows you to use `--seed` to deterministically reproduce
86
+ # # test failures related to randomization by passing the same `--seed` value
87
+ # # as the one that triggered the failure.
88
+ # Kernel.srand config.seed
89
+ end
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,9 @@
1
+ module Calculator
2
+ class Max
3
+ def run(left, right)
4
+ max = left
5
+ max = right if right > left
6
+ max
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ require_relative "calculator/max"
2
+
3
+ module Calculator
4
+ end