rspec-given 2.4.5 → 3.0.0.beta.2

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -2
  3. data/Gemfile.lock +8 -10
  4. data/README.md +50 -34
  5. data/README.old +720 -0
  6. data/Rakefile +23 -17
  7. data/TODO +13 -0
  8. data/examples/example_helper.rb +8 -1
  9. data/examples/integration/and_spec.rb +6 -11
  10. data/examples/integration/focused_line_spec.rb +2 -1
  11. data/examples/integration/given_spec.rb +19 -9
  12. data/examples/integration/invariant_spec.rb +6 -6
  13. data/examples/integration/then_spec.rb +0 -1
  14. data/examples/loader.rb +4 -0
  15. data/examples/minitest_helper.rb +38 -0
  16. data/examples/stack/stack_spec.rb +2 -3
  17. data/lib/given.rb +2 -0
  18. data/lib/rspec/given.rb +1 -19
  19. data/rakelib/bundler_fix.rb +17 -0
  20. data/rakelib/gemspec.rake +161 -0
  21. data/rakelib/metrics.rake +30 -0
  22. data/rakelib/preview.rake +14 -0
  23. data/spec/lib/{rspec/given → given}/evaluator_spec.rb +1 -1
  24. data/spec/lib/{rspec/given → given}/ext/numeric_spec.rb +2 -2
  25. data/spec/lib/{rspec/given → given}/ext/numeric_specifications.rb +0 -0
  26. data/spec/lib/{rspec/given → given}/extensions_spec.rb +2 -2
  27. data/spec/lib/given/failure_matcher_spec.rb +77 -0
  28. data/spec/lib/given/failure_spec.rb +49 -0
  29. data/spec/lib/given/file_cache_spec.rb +26 -0
  30. data/spec/lib/{rspec/given → given}/fuzzy_number_spec.rb +2 -2
  31. data/spec/lib/{rspec/given → given}/have_failed_spec.rb +5 -4
  32. data/spec/lib/{rspec/given → given}/lexical_purity_spec.rb +0 -0
  33. data/spec/lib/given/line_extractor_spec.rb +84 -0
  34. data/spec/lib/{rspec/given → given}/module_methods_spec.rb +2 -2
  35. data/spec/lib/{rspec/given → given}/natural_assertion_spec.rb +4 -36
  36. data/spec/lib/{rspec/given → given}/options_spec.rb +33 -33
  37. data/spec/spec_helper.rb +20 -0
  38. data/spec/support/faux_then.rb +2 -2
  39. data/spec/support/natural_assertion_control.rb +1 -1
  40. metadata +35 -42
  41. data/examples/integration/failing_spec.rb +0 -5
  42. data/lib/rspec/given/configure.rb +0 -20
  43. data/lib/rspec/given/core.rb +0 -9
  44. data/lib/rspec/given/evaluator.rb +0 -39
  45. data/lib/rspec/given/ext/numeric.rb +0 -32
  46. data/lib/rspec/given/extensions.rb +0 -262
  47. data/lib/rspec/given/failure.rb +0 -53
  48. data/lib/rspec/given/file_cache.rb +0 -19
  49. data/lib/rspec/given/fuzzy_number.rb +0 -70
  50. data/lib/rspec/given/fuzzy_shortcuts.rb +0 -1
  51. data/lib/rspec/given/have_failed.rb +0 -77
  52. data/lib/rspec/given/line_extractor.rb +0 -43
  53. data/lib/rspec/given/module_methods.rb +0 -70
  54. data/lib/rspec/given/monkey.rb +0 -42
  55. data/lib/rspec/given/natural_assertion.rb +0 -193
  56. data/lib/rspec/given/rspec1_given.rb +0 -11
  57. data/lib/rspec/given/version.rb +0 -10
  58. data/spec/lib/rspec/given/failure_spec.rb +0 -17
  59. data/spec/lib/rspec/given/file_cache_spec.rb +0 -28
  60. data/spec/lib/rspec/given/line_extractor_spec.rb +0 -86
@@ -0,0 +1,30 @@
1
+ require './rakelib/bundler_fix'
2
+
3
+ METRICS_FILES = FileList['lib/**/*.rb']
4
+
5
+ task :check_flog do
6
+ sh "type flog >/dev/null 2>&1", :verbose => false do |status|
7
+ fail "Install flog to generate complexity metrics" unless status
8
+ end
9
+ end
10
+
11
+ task :check_flay do
12
+ sh "type flay >/dev/null 2>&1", :verbose => false do |status|
13
+ fail "Install flay to generate complexity metrics" unless status
14
+ end
15
+ end
16
+
17
+ desc "Run complexity metrics"
18
+ task :flog, [:all] => :check_flog do |t, args|
19
+ flags = args.all ? "--all" : ""
20
+ nobundle do
21
+ sh "flog #{flags} #{METRICS_FILES}"
22
+ end
23
+ end
24
+
25
+ desc "Run duplication metrics"
26
+ task :flay => :check_flay do
27
+ nobundle do
28
+ sh "flay #{METRICS_FILES}"
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ require './rakelib/bundler_fix'
2
+
3
+ task :check_preview do
4
+ sh "type ghpreview >/dev/null 2>&1", :verbose => false do |status|
5
+ fail "Install ghpreview to generate a local REAMDE preview page" unless status
6
+ end
7
+ end
8
+
9
+ desc "Generate the GitHub readme locally"
10
+ task :preview => :check_preview do
11
+ nobundle do
12
+ sh "ghpreview #{FileList['README.*']}"
13
+ end
14
+ end
@@ -26,6 +26,6 @@ end
26
26
  describe "Evaluator with error object" do
27
27
  FauxThen { 1 }
28
28
  When(:result) { ev.eval_string("fail 'XYZ'") }
29
- Then { result.class.should == RSpec::Given::EvalErr }
29
+ Then { result.class.should == Given::EvalErr }
30
30
  Then { result.inspect.should == "RuntimeError: XYZ" }
31
31
  end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'spec_helper'
3
- require 'rspec/given'
4
- require 'rspec/given/fuzzy_shortcuts'
3
+ require 'given'
4
+ require 'given/fuzzy_shortcuts'
5
5
 
6
6
  describe "Numeric Extensions" do
7
7
  use_natural_assertions_if_supported
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RSpec::Given::ClassExtensions do
3
+ describe Given::ClassExtensions do
4
4
  let(:trace) { [] }
5
5
 
6
6
  describe "Given with var" do
@@ -195,7 +195,7 @@ describe "use_natural_assertions" do
195
195
 
196
196
  When(:result) { CONTEXT.use_natural_assertions }
197
197
 
198
- if RSpec::Given::NATURAL_ASSERTIONS_SUPPORTED
198
+ if ::Given::NATURAL_ASSERTIONS_SUPPORTED
199
199
  Then { result.should_not have_failed }
200
200
  else
201
201
  Then { result.should have_failed(ArgumentError) }
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+ require 'given/failure_matcher'
3
+
4
+ module FailureMatcherSpec
5
+ OtherError = Class.new(StandardError)
6
+ CustomError = Class.new(StandardError)
7
+ SubError = Class.new(CustomError)
8
+ NotMetError = RSpec::Expectations::ExpectationNotMetError
9
+
10
+ describe Given::FailureMatcher do
11
+ Given(:error) { CustomError.new("CUSTOM") }
12
+
13
+ Given(:failure_result) { Given::Failure.new(error) }
14
+
15
+ context "with matching failure results" do
16
+ Then { Failure(CustomError, "CUSTOM").matches?(failure_result) }
17
+ Then { Failure(CustomError, /CUSTOM/).matches?(failure_result) }
18
+ Then { Failure(CustomError).matches?(failure_result) }
19
+ Then { Failure(StandardError).matches?(failure_result) }
20
+ Then { Failure().matches?(failure_result) }
21
+ end
22
+
23
+ context "with non-matching results" do
24
+ Then {
25
+ expect {
26
+ Failure(StandardError).matches?(Object.new)
27
+ }.to raise_error(NotMetError,
28
+ /Expected.*StandardError, but nothing failed/)
29
+ }
30
+
31
+ Then {
32
+ expect {
33
+ Failure(StandardError, /CUSTOM/).matches?(Object.new)
34
+ }.to raise_error(NotMetError,
35
+ /Expected.*StandardError.*matching.*CUSTOM.*, but nothing failed/)
36
+ }
37
+
38
+ Then {
39
+ expect {
40
+ Failure(StandardError, /OTHER/).matches?(failure_result)
41
+ }.to raise_error(NotMetError,
42
+ /Expected.*StandardError matching.*OTHER.*, but got.*CustomError.*CUSTOM/)
43
+ }
44
+
45
+ Then {
46
+ expect {
47
+ Failure(OtherError, /CUSTOM/).matches?(failure_result)
48
+ }.to raise_error(NotMetError,
49
+ /Expected.*OtherError matching.*CUSTOM.*, but got.*CustomError.*CUSTOM/)
50
+ }
51
+
52
+ Then {
53
+ expect {
54
+ Failure(SubError, /CUSTOM/).matches?(failure_result)
55
+ }.to raise_error(NotMetError,
56
+ /Expected.*SubError matching.*CUSTOM.*, but got.*CustomError.*CUSTOM/)
57
+ }
58
+
59
+ Then {
60
+ expect {
61
+ Failure(OtherError).matches?(failure_result)
62
+ }.to raise_error(NotMetError,
63
+ /Expected.*OtherError, but got.*CustomError.*CUSTOM/)
64
+ }
65
+ end
66
+
67
+ describe "==" do
68
+ Then { failure_result == Failure(CustomError) }
69
+ Then { Failure(CustomError) == failure_result }
70
+ end
71
+
72
+ describe "!=" do
73
+ Then { failure_result != Failure(SubError) }
74
+ Then { Failure(SubError) == failure_result }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'given/failure'
3
+
4
+ describe Given::Failure do
5
+ OtherError = Class.new(StandardError)
6
+
7
+ Given(:exception) { StandardError.new("Oops") }
8
+ Given(:failure) { Given::Failure.new(exception) }
9
+
10
+ Then { failure.is_a?(Given::Failure).should be_true }
11
+
12
+ describe "general operations" do
13
+ Then { expect { failure.to_s }.to raise_error(StandardError, "Oops") }
14
+ Then { expect { failure.call }.to raise_error(StandardError, "Oops") }
15
+ Then { expect { failure.nil? }.to raise_error(StandardError, "Oops") }
16
+ Then { expect { failure == 0 }.to raise_error(StandardError, "Oops") }
17
+ Then { expect { failure != 0 }.to raise_error(StandardError, "Oops") }
18
+ Then { expect { failure =~ 0 }.to raise_error(StandardError, "Oops") }
19
+ Then { expect { ! failure }.to raise_error(StandardError, "Oops") }
20
+ end
21
+
22
+ describe "should raise error" do
23
+ Then { failure.should raise_error(StandardError, "Oops") }
24
+ Then { failure.should raise_error(StandardError) }
25
+ Then { failure.should raise_error }
26
+ end
27
+
28
+ describe "== have_failed" do
29
+ Then { failure == have_failed(StandardError, "Oops") }
30
+ Then { failure == have_failed(StandardError) }
31
+ Then { failure == have_failed }
32
+ end
33
+
34
+ describe "!= have_failed" do
35
+ Then { failure != have_failed() }
36
+ end
37
+
38
+ describe "== Failure" do
39
+ Then { failure == Failure(StandardError, "Oops") }
40
+ Then { failure == Failure(StandardError) }
41
+ Then { failure == Failure() }
42
+ end
43
+
44
+ describe "!= Failure" do
45
+ Then { expect { failure != Object.new }.to raise_error(StandardError) }
46
+ Then { failure != Failure() }
47
+ end
48
+
49
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Given
4
+
5
+ DESCRIBE_LINE = __LINE__
6
+ describe FileCache do
7
+ Given(:file_name) { __FILE__ }
8
+ Given(:cache) { FileCache.new }
9
+
10
+ When(:result) { cache.get(file_name) }
11
+
12
+ context "when reading the file" do
13
+ Then { result[DESCRIBE_LINE].should =~ /describe FileCache do/ }
14
+ Then { result.size.should == MAX_LINE }
15
+ end
16
+
17
+ context "when getting the same file twice" do
18
+ Given { cache.should_receive(:read_lines).once.and_return(["A"]) }
19
+ When(:result2) { cache.get(file_name) }
20
+ Then { result.should == ["A"] }
21
+ Then { result2.should == ["A"] }
22
+ end
23
+ end
24
+ end
25
+
26
+ MAX_LINE = __LINE__
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RSpec::Given::Fuzzy::FuzzyNumber do
3
+ describe Given::Fuzzy::FuzzyNumber do
4
4
  use_natural_assertions_if_supported
5
- include RSpec::Given::Fuzzy
5
+ include Given::Fuzzy
6
6
 
7
7
  describe "attributes" do
8
8
  Given(:number) { about(10).delta(0.0001) }
@@ -1,10 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#have_failed" do
3
+ module HaveFailedSpec
4
4
  CustomError = Class.new(StandardError)
5
5
  DifferentError = Class.new(StandardError)
6
6
  ExpectationError = RSpec::Expectations::ExpectationNotMetError
7
7
 
8
+ describe "#have_failed" do
8
9
  context "with a failure" do
9
10
  When(:result) { fail CustomError, "Ouch" }
10
11
 
@@ -40,7 +41,7 @@ describe "#have_failed" do
40
41
 
41
42
  context "with a pending exception" do
42
43
  When(:result) { fail RSpec::Core::Pending::PendingDeclaredInExample, "Required pending in example ... please ignore" }
43
- Then { RSpec::Given.fail_with "This example should have been pending" }
44
+ Then { Given.fail_with "This example should have been pending" }
44
45
  end
45
46
 
46
47
  context "with a non-failure" do
@@ -55,15 +56,15 @@ describe "#have_failed" do
55
56
  context "with failure" do
56
57
  When(:result) { fail CustomError, "Ouch" }
57
58
  Then { result == have_failed(CustomError, "Ouch") }
58
- Then { ! (result != have_failed(CustomError, "Ouch")) }
59
+ Then { ! (result != have_failed) }
59
60
  Then { expect { result == :something }.to raise_error(CustomError, "Ouch") }
60
61
  end
61
62
 
62
63
  context "with different failure" do
63
64
  When(:result) { fail DifferentError, "Ouch" }
64
65
  Then { ! (result == have_failed(CustomError, "Ouch")) }
65
- Then { result != have_failed(CustomError, "Ouch") }
66
66
  end
67
67
 
68
68
  end
69
69
  end
70
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ module Given
4
+
5
+ describe LineExtractor do
6
+
7
+ class FauxFileCache
8
+ def initialize(lines)
9
+ @lines = lines.split(/\n/).map { |ln| ln + "\n" }
10
+ end
11
+ def get(file_name)
12
+ @lines
13
+ end
14
+ end
15
+
16
+ Given(:line) { 2 }
17
+ Given(:file_cache) { FauxFileCache.new(input) }
18
+ Given(:extractor) { LineExtractor.new(file_cache) }
19
+
20
+ When(:result) { extractor.line("FILENAME", line) }
21
+
22
+ describe "reading a line" do
23
+ Given(:input) {
24
+ " Now is the time\n" +
25
+ " for all good men\n" +
26
+ " to come to the aid\n" +
27
+ " of their fellowmen\n"
28
+ }
29
+ Given(:expected_line) { " for all good men\n" }
30
+ Then { result.should == expected_line }
31
+ end
32
+
33
+ context "when the line doesn't exist" do
34
+ Given(:input) { "" }
35
+ Then { result.should be_nil }
36
+ end
37
+
38
+ context "when the line has leading and trailing white space" do
39
+ Given(:input) {
40
+ " Then { y } \n" +
41
+ " Then { x }\n"
42
+ }
43
+ Then { result.should == " Then { x }\n" }
44
+ end
45
+
46
+ context "when the Then is split over several lines with {}" do
47
+ Given(:input) {
48
+ "describe 'foobar' do\n" +
49
+ " Then {\n" +
50
+ " x\n" +
51
+ " }\n" +
52
+ "end\n"
53
+ }
54
+ Then { result.should == " Then {\n x\n }\n" }
55
+ end
56
+
57
+ context "when the Then is has blank lines" do
58
+ Given(:input) {
59
+ "describe 'foobar' do\n" +
60
+ " Then {\n\n" +
61
+ " x\n" +
62
+ " }\n" +
63
+ "end\n"
64
+ }
65
+ Then { result.should == " Then {\n\n x\n }\n" }
66
+ end
67
+
68
+ context "when the Then is split over several lines with do/end" do
69
+ Given(:input) {
70
+ "describe 'foobar' do\n" +
71
+ " Then do\n" +
72
+ " x\n" +
73
+ " end\n" +
74
+ "end\n"
75
+ }
76
+ Then { result.should == " Then do\n x\n end\n" }
77
+ end
78
+
79
+ describe "converting to a string" do
80
+ Given(:input) { "" }
81
+ Then { extractor.to_s.should =~ /line *extractor/i }
82
+ end
83
+ end
84
+ end
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe "RSpec::Given.use_natural_assertions" do
4
4
  context "when in JRuby" do
5
- When(:result) { RSpec::Given.use_natural_assertions }
5
+ When(:result) { ::Given.use_natural_assertions }
6
6
 
7
- if RSpec::Given::NATURAL_ASSERTIONS_SUPPORTED
7
+ if ::Given::NATURAL_ASSERTIONS_SUPPORTED
8
8
  Then { result.should_not have_failed }
9
9
  else
10
10
  Then { result.should have_failed(ArgumentError) }
@@ -1,9 +1,9 @@
1
1
  require 'rspec/given'
2
2
  require 'spec_helper'
3
3
 
4
- describe RSpec::Given::NaturalAssertion do
4
+ describe Given::NaturalAssertion do
5
5
  before do
6
- pending "Natural Assertions disabled for JRuby" unless RSpec::Given::NATURAL_ASSERTIONS_SUPPORTED
6
+ pending "Natural Assertions disabled for JRuby" unless Given::NATURAL_ASSERTIONS_SUPPORTED
7
7
  end
8
8
 
9
9
  describe "#content?" do
@@ -17,38 +17,6 @@ describe RSpec::Given::NaturalAssertion do
17
17
  end
18
18
  end
19
19
 
20
- describe "detecting RSpec Assertions" do
21
- context "with should" do
22
- FauxThen { a.should == 1 }
23
- Then { na.should be_using_rspec_assertion }
24
- end
25
-
26
- context "with should_not" do
27
- FauxThen { a.should_not == 1 }
28
- Then { na.should be_using_rspec_assertion }
29
- end
30
-
31
- context "with expect/to" do
32
- FauxThen { expect(a).to eq(1) }
33
- Then { na.should be_using_rspec_assertion }
34
- end
35
-
36
- context "with expect/not_to" do
37
- FauxThen { expect(a).not_to eq(1) }
38
- Then { na.should be_using_rspec_assertion }
39
- end
40
-
41
- context "with expect and block" do
42
- FauxThen { expect { a }.to eq(1) }
43
- Then { na.should be_using_rspec_assertion }
44
- end
45
-
46
- context "with natural assertion" do
47
- FauxThen { a == 1 }
48
- Then { na.should_not be_using_rspec_assertion }
49
- end
50
- end
51
-
52
20
  describe "failure messages" do
53
21
  let(:msg) { na.message }
54
22
  Invariant { msg.should =~ /^FauxThen expression/ }
@@ -166,7 +134,7 @@ describe RSpec::Given::NaturalAssertion do
166
134
  context "with no statements" do
167
135
  FauxThen { }
168
136
  When(:result) { na.message }
169
- Then { result.should_not have_failed(RSpec::Given::InvalidThenError) }
137
+ Then { result.should_not have_failed }
170
138
  end
171
139
 
172
140
  context "with multiple statements" do
@@ -175,7 +143,7 @@ describe RSpec::Given::NaturalAssertion do
175
143
  ary[1] == 3
176
144
  }
177
145
  When(:result) { na.message }
178
- Then { result.should have_failed(RSpec::Given::InvalidThenError, /multiple.*statements/i) }
146
+ Then { result.should have_failed(Given::InvalidThenError, /multiple.*statements/i) }
179
147
  end
180
148
 
181
149
  end