rspec_gandalf 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1 +1,77 @@
1
- # Test
1
+ # rspec_gandalf
2
+
3
+ Because some objects shall not pass.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rspec_gandalf'
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rspec_gandalf
18
+
19
+ ## Usage
20
+
21
+
22
+ 1. Create a file named "gandalf_test.rb"
23
+ 2. Put this:
24
+
25
+ ```ruby
26
+
27
+ # coding: utf-8
28
+ require 'rspec_gandalf'
29
+
30
+ class Balrog;end;
31
+
32
+ class Men;end;
33
+
34
+ class Hobbit;end;
35
+
36
+ class TrollRog < Balrog;end;
37
+
38
+ class PretaGil < Balrog;end;
39
+
40
+ describe Men do
41
+ it { shall pass }
42
+ end
43
+
44
+ describe Balrog do
45
+ it { shall pass }
46
+ end
47
+
48
+ describe TrollRog do
49
+ it { shall pass }
50
+ end
51
+
52
+ describe PretaGil do
53
+ it { shall_not pass }
54
+ end
55
+
56
+ ```
57
+
58
+ 3. Test it
59
+
60
+ $ rspec gandalf_test.rb
61
+
62
+ 4. See the result
63
+
64
+ 1) Balrog
65
+ Failure/Error: it { shall pass }
66
+ ATTENTION: Balrog is a flame of Udun and SHALL NOT PASS.
67
+
68
+ 2) TrollRog
69
+ Failure/Error: it { shall pass }
70
+ RUN YOU FOOL. Your disguise doesn't trick me.
71
+ ATTENTION: TrollRog is a flame of Udun and SHALL NOT PASS
72
+ 4 examples, 2 failures
73
+ Failed examples:
74
+
75
+ rspec ./test.rb:19 # Balrog
76
+ rspec ./test.rb:23 # TrollRog
77
+
@@ -6,8 +6,9 @@ RSpec::Matchers.define :pass do
6
6
  end
7
7
 
8
8
  failure_message_for_should do |described_object|
9
- if @class_ancestors_contains_balrog
10
- "RUN YOU FOOL. You cannot trick me. \nATTENTION: #{described_object.class.name} is a flame of Udun and SHALL NOT PASS"
9
+
10
+ if class_ancestors_contains_balrog?(described_object.class)
11
+ "RUN YOU FOOL. Your disguise doesn't trick me. \nATTENTION: #{described_object.class.name} is a flame of Udun and SHALL NOT PASS"
11
12
  else
12
13
  "ATTENTION: #{described_object.class.name} is a flame of Udun and SHALL NOT PASS."
13
14
  end
@@ -23,7 +24,12 @@ RSpec::Matchers.define :pass do
23
24
 
24
25
  def is_balrog?(described_class)
25
26
  class_name_contains_balrog = !!(described_class.name.match(/balrog/i))
26
- @class_ancestors_contains_balrog = described_class.ancestors.reduce(class_name_contains_balrog) { |mem, class_name|
27
+ class_name_contains_balrog || class_ancestors_contains_balrog?(described_class)
28
+ end
29
+
30
+ def class_ancestors_contains_balrog?(described_class)
31
+ valid_ancestors = described_class.ancestors[1..(described_class.ancestors.size)]
32
+ valid_ancestors.reduce(false) { |mem, class_name|
27
33
  (mem || !!(class_name.name.match(/balrog/i)))
28
34
  }
29
35
  end
@@ -6,14 +6,14 @@ Gem::Specification.new do |gem|
6
6
  gem.platform = Gem::Platform::RUBY
7
7
  gem.description = %q{Bad tests shall not pass!}
8
8
  gem.summary = %q{One does not simply pass the tests!}
9
- gem.homepage = "https://github.com/codus/rest_api"
9
+ gem.homepage = "https://github.com/viniciusoyama/rspec_gandalf"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "rspec_gandalf"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = "0.1"
16
+ gem.version = "0.1.1"
17
17
 
18
18
  gem.add_dependency('rspec', '~> 2.13')
19
19
  end
@@ -1,6 +1,5 @@
1
1
  # coding: utf-8
2
-
3
- require 'spec_helper'
2
+ require 'rspec_gandalf'
4
3
 
5
4
  class Balrog;end;
6
5
 
@@ -12,10 +11,18 @@ class TrollRog < Balrog;end;
12
11
 
13
12
  class PretaGil < Balrog;end;
14
13
 
15
- describe Hobbit do
14
+ describe Men do
16
15
  it { shall pass }
17
16
  end
18
17
 
19
- describe PretaGil do
18
+ describe Balrog do
20
19
  it { shall pass }
21
20
  end
21
+
22
+ describe TrollRog do
23
+ it { shall pass }
24
+ end
25
+
26
+ describe PretaGil do
27
+ it { shall_not pass }
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_gandalf
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -44,7 +44,7 @@ files:
44
44
  - rspec_gandalf.gemspec
45
45
  - spec/rspec_gandalf/rspec_gandalf_spec.rb
46
46
  - spec/spec_helper.rb
47
- homepage: https://github.com/codus/rest_api
47
+ homepage: https://github.com/viniciusoyama/rspec_gandalf
48
48
  licenses: []
49
49
  post_install_message:
50
50
  rdoc_options: []