contracts-noop 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72af6ffd8d554f4741ec0e0078b7cabce4efd302
4
- data.tar.gz: 39da2879fdc9b64da333d851ef70027824aead66
3
+ metadata.gz: ebdb8aea3de3f778721b958604c0d5c7aebe7dec
4
+ data.tar.gz: a39f7b511e1f9757a741e1d1e9b922fd089db0dd
5
5
  SHA512:
6
- metadata.gz: badd071477ac9081468264e18c04feb0e8048b06ea8058f7de94132f03842b877d9e7919e7e6f979ed20e04f8ba316cde5011c6a5beafe60589e52eb6ca2e74d
7
- data.tar.gz: 6e8a92e48601d4443661556ff457796a9152d03de9d94f23106f44e41da8a16bb8810dd3200fb22d8e04da3733c5c7f7ef3b5803738aaa8b561db24bebb2d7dd
6
+ metadata.gz: ddc9e28264b5130f186b44f8292be67fccbebb20c56d2235882bdc31e079ab688486dc1e082e1b3acfb83c0aa8fbee7ff40ffae9ddfa3349ca693af649801c16
7
+ data.tar.gz: ce509f8f9f3897a127021e92d903865bcb9638274a080b240b07571ad0e87a7d61471cfe15220f7aa2be2e6f1d3495277c1f8c9cac7763d09c621d26a75711fb
@@ -0,0 +1,3 @@
1
+ [submodule "fixtures/contracts.ruby"]
2
+ path = fixtures/contracts.ruby
3
+ url = https://github.com/egonSchiele/contracts.ruby
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in contracts-noop.gemspec
4
4
  gemspec
5
+
6
+ gem "rspec"
@@ -1,7 +1,12 @@
1
1
  require "contracts/noop/version"
2
+ require "contracts/noop/loader"
2
3
 
3
4
  module Contracts
4
5
  module Noop
5
- # Your code goes here...
6
+ def self.when_contracts_available(&blk)
7
+ Loader.new(lambda { require "contracts" },
8
+ lambda { require "contracts/noop/fake" })
9
+ .load(&blk)
10
+ end
6
11
  end
7
12
  end
@@ -0,0 +1,67 @@
1
+ module Contracts
2
+ def self.included(base) common(base) end
3
+ def self.extended(base) common(base) end
4
+
5
+ def self.common(base)
6
+ base.class_eval do
7
+ def Contract(*args)
8
+ end
9
+
10
+ def self.Contract(*args)
11
+ end
12
+ end
13
+
14
+ unless base <= eigenclass_of(Object)
15
+ eigenclass_of(base).send(:include, Contracts)
16
+ end
17
+ end
18
+
19
+ def self.eigenclass_of(base)
20
+ class << base; self; end
21
+ end
22
+
23
+ module Invariants
24
+ def self.included(base) common(base) end
25
+ def self.extended(base) common(base) end
26
+
27
+ def self.common(base)
28
+ base.class_eval do
29
+ def Invariant(*args)
30
+ end
31
+
32
+ def self.Invariant(*args)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ module Modules
39
+ end
40
+
41
+ class CallableClass
42
+ def self.[](*args)
43
+ end
44
+ end
45
+
46
+ Num = CallableClass
47
+ Or = CallableClass
48
+ Bool = CallableClass
49
+ Any = CallableClass
50
+ Args = CallableClass
51
+ Func = CallableClass
52
+ ArrayOf = CallableClass
53
+ Pos = CallableClass
54
+ Neg = CallableClass
55
+ Nat = CallableClass
56
+ None = CallableClass
57
+ Xor = CallableClass
58
+ RespondTo = CallableClass
59
+ And = CallableClass
60
+ Send = CallableClass
61
+ Not = CallableClass
62
+ Maybe = CallableClass
63
+ HashOf = CallableClass
64
+ Exactly = CallableClass
65
+ Eq = CallableClass
66
+
67
+ end
@@ -0,0 +1,24 @@
1
+ module Contracts
2
+ module Noop
3
+ class Loader
4
+ def initialize(load_strategy, rescue_strategy)
5
+ @load_strategy = load_strategy
6
+ @rescue_strategy = rescue_strategy
7
+ end
8
+
9
+ def load(&blk)
10
+ blk.call if _load
11
+ end
12
+
13
+ private
14
+
15
+ def _load
16
+ @load_strategy.call
17
+ true
18
+ rescue LoadError
19
+ @rescue_strategy.call
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  module Contracts
2
2
  module Noop
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,6 @@
1
+ require "contracts/noop/fake"
2
+
3
+ # NOTE kinda strange spec, just defines things, if they don't blow up, then everything works
4
+
5
+ load "./fixtures/contracts.ruby/spec/support.rb"
6
+ load "./fixtures/contracts.ruby/spec/fixtures/fixtures.rb"
@@ -0,0 +1,55 @@
1
+ require "contracts/noop/loader"
2
+
3
+ module Contracts
4
+ module Noop
5
+ RSpec.describe Loader do
6
+ let(:spy) { double("spy") }
7
+ let(:rescue_strategy) { lambda { spy.failed } }
8
+
9
+ subject { described_class.new(load_strategy, rescue_strategy) }
10
+
11
+ describe "#load" do
12
+ context "when able to load" do
13
+ let(:load_strategy) { lambda { spy.load } }
14
+
15
+ it "executes block" do
16
+ expect(spy).to receive(:load).ordered.once
17
+ expect(spy).to receive(:done).ordered.once
18
+ expect(spy).not_to receive(:failed)
19
+
20
+ subject.load do
21
+ spy.done
22
+ end
23
+ end
24
+
25
+ it "does not rescue if block failed with LoadError" do
26
+ expect(spy).to receive(:load).ordered.once
27
+ expect(spy).not_to receive(:done)
28
+ expect(spy).not_to receive(:failed)
29
+
30
+ expect {
31
+ subject.load do
32
+ raise LoadError
33
+ spy.done
34
+ end
35
+ }.to raise_error(LoadError)
36
+ end
37
+ end
38
+
39
+ context "when unable to load" do
40
+ let(:load_strategy) { lambda { raise LoadError } }
41
+
42
+ it "doesn't execute block and call rescue_strategy" do
43
+ expect(spy).not_to receive(:load)
44
+ expect(spy).not_to receive(:done)
45
+ expect(spy).to receive(:failed)
46
+
47
+ subject.load do
48
+ spy.done
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,26 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ config.filter_run :focus
11
+ config.run_all_when_everything_filtered = true
12
+
13
+ config.disable_monkey_patching!
14
+
15
+ config.warnings = true
16
+
17
+ if config.files_to_run.one?
18
+ config.default_formatter = 'doc'
19
+ end
20
+
21
+ config.profile_examples = 10
22
+
23
+ config.order = :random
24
+
25
+ Kernel.srand config.seed
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contracts-noop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksii Fedorov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,13 +52,20 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - ".gitignore"
55
+ - ".gitmodules"
56
+ - ".rspec"
55
57
  - Gemfile
56
58
  - LICENSE.txt
57
59
  - README.md
58
60
  - Rakefile
59
61
  - contracts-noop.gemspec
60
62
  - lib/contracts/noop.rb
63
+ - lib/contracts/noop/fake.rb
64
+ - lib/contracts/noop/loader.rb
61
65
  - lib/contracts/noop/version.rb
66
+ - spec/contracts/noop/fake_spec.rb
67
+ - spec/contracts/noop/loader_spec.rb
68
+ - spec/spec_helper.rb
62
69
  homepage: https://github.com/waterlink/contracts-noop
63
70
  licenses:
64
71
  - MIT
@@ -83,4 +90,7 @@ rubygems_version: 2.2.2
83
90
  signing_key:
84
91
  specification_version: 4
85
92
  summary: Allows usage of contracts.ruby as a development dependency
86
- test_files: []
93
+ test_files:
94
+ - spec/contracts/noop/fake_spec.rb
95
+ - spec/contracts/noop/loader_spec.rb
96
+ - spec/spec_helper.rb