rails_dt 0.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.yardopts +2 -0
  4. data/Gemfile +14 -0
  5. data/MIT-LICENSE +1 -1
  6. data/README.md +43 -135
  7. data/lib/dt.rb +31 -215
  8. data/lib/dt/config.rb +74 -0
  9. data/lib/dt/instance.rb +117 -0
  10. data/lib/rails_dt.rb +3 -2
  11. data/lib/rails_dt/version.rb +4 -0
  12. data/rails_dt.gemspec +12 -50
  13. data/spec/lib/dt/config_spec.rb +76 -0
  14. data/spec/lib/dt/instance_spec.rb +173 -0
  15. data/spec/lib/dt_spec.rb +14 -0
  16. data/spec/lib/rails_dt_spec.rb +6 -0
  17. data/spec/lib/spec/alias_method_matcher_spec.rb +16 -0
  18. data/spec/lib/spec/context_when_spec.rb +32 -0
  19. data/spec/lib/spec/let_m_spec.rb +104 -0
  20. data/spec/lib/spec/use_custom_let_spec.rb +46 -0
  21. data/spec/spec_helper.rb +6 -0
  22. data/spec/support/00extend_x.rb +23 -0
  23. data/spec/support/alias_method_matcher.rb +20 -0
  24. data/spec/support/context_when.rb +39 -0
  25. data/spec/support/let_m.rb +27 -0
  26. data/spec/support/use_custom_let.rb +80 -0
  27. metadata +43 -52
  28. data/README.html +0 -171
  29. data/Rakefile +0 -68
  30. data/VERSION.yml +0 -4
  31. data/generators/rails_dt/USAGE +0 -11
  32. data/generators/rails_dt/WARNING +0 -2
  33. data/generators/rails_dt/rails_dt_generator.rb +0 -9
  34. data/generators/rails_dt/templates/INSTALL +0 -20
  35. data/generators/rails_dt/templates/dt.css +0 -27
  36. data/generators/rails_dt/templates/dt.rb +0 -4
  37. data/init.rb +0 -2
  38. data/lib/dt/action_controller_extensions.rb +0 -29
  39. data/lib/generators/rails_dt/USAGE +0 -11
  40. data/lib/generators/rails_dt/rails_dt_generator.rb +0 -9
  41. data/lib/generators/rails_dt/templates/INSTALL +0 -20
  42. data/lib/generators/rails_dt/templates/dt.css +0 -27
  43. data/lib/generators/rails_dt/templates/dt.rb +0 -4
@@ -0,0 +1,14 @@
1
+
2
+ RSpec.describe DT do
3
+ subject { described_class.public_send(m) }
4
+
5
+ describe ".conf" do
6
+ let_m
7
+ it { is_expected.to be_a described_class::Config }
8
+ end
9
+
10
+ describe ".instance" do
11
+ let_m
12
+ it { is_expected.to be_a described_class::Instance }
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+
2
+ describe RailsDt do
3
+ describe "VERSION" do
4
+ it { expect(described_class::VERSION).to eq "1.2.0" }
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+
2
+ RSpec.describe "`alias_method` matcher" do
3
+ describe "klass" do
4
+ let(:klass) do
5
+ Class.new do
6
+ def is_one
7
+ end
8
+ alias_method :one?, :is_one
9
+ end
10
+ end
11
+
12
+ subject { klass.new }
13
+
14
+ it { is_expected.to alias_method(:one?, :is_one) }
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+
2
+ require "json"
3
+
4
+ RSpec.describe ".context_when" do
5
+ context "when default" do
6
+ context_when a: 1, "b" => 2, x: "y" do
7
+ description = self.description
8
+ it { expect(description).to eq 'when {a: 1, "b"=>2, x: "y"}' }
9
+ it { expect { c }.to raise_error(NameError, /^undefined local variable or method `c'/) }
10
+ it { expect([a, b, x]).to eq [1, 2, "y"] }
11
+ end
12
+ end
13
+
14
+ context "when customized" do
15
+ context_when({a: 1, x: "y"}, format_proc: ->(h) { "when #{h.to_json}" }) do
16
+ description = self.description
17
+ it { expect(description).to eq 'when {"a":1,"x":"y"}' }
18
+ it { expect([a, x]).to eq [1, "y"] }
19
+ end
20
+ end
21
+
22
+ context "with `def` in the block" do
23
+ context_when a: 1 do
24
+ def ar
25
+ [a, 2]
26
+ end
27
+
28
+ it { expect(a).to eq 1 }
29
+ it { expect(ar).to eq [1, 2] }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,104 @@
1
+
2
+ RSpec.describe ".let_m" do
3
+ describe "describe/it scope" do
4
+ describe "#some_method" do
5
+ let_m
6
+ self_m = m
7
+ it { expect(self_m).to eq :some_method }
8
+ it { expect(m).to eq :some_method }
9
+ end
10
+ end
11
+
12
+ describe "`let` argument handling" do
13
+ describe "#some_method" do
14
+ let_m(:x)
15
+ self_x = x
16
+ it { expect(self_x).to eq :some_method }
17
+ it { expect(x).to eq :some_method }
18
+ end
19
+ end
20
+
21
+ context "when invalid argument like ..." do
22
+ def self.doit
23
+ # OPTIMIZE: There's a more optimal implementation of this in `extract_to_spec.rb`.
24
+ begin; let_m; rescue ArgumentError => e; let(:message) { e.message }; end
25
+ end
26
+
27
+ describe "#some_method!!" do
28
+ doit
29
+ it { expect(message).to eq "Unknown description format: \"#some_method!!\"" }
30
+ end
31
+
32
+ describe "#some method" do
33
+ doit
34
+ it { expect(message).to eq "Unknown description format: \"#some method\"" }
35
+ end
36
+
37
+ describe "method" do
38
+ doit
39
+ it { expect(message).to eq "Unknown description format: \"method\"" }
40
+ end
41
+ end
42
+
43
+ context "when valid argument like ..." do
44
+ describe "#some_method" do
45
+ let_m
46
+ it { expect(m).to eq :some_method }
47
+ end
48
+
49
+ describe "#some_method?" do
50
+ let_m
51
+ it { expect(m).to eq :some_method? }
52
+ end
53
+
54
+ describe "#some_method!" do
55
+ let_m
56
+ it { expect(m).to eq :some_method! }
57
+ end
58
+
59
+ describe ".some_method" do
60
+ let_m
61
+ it { expect(m).to eq :some_method }
62
+ end
63
+
64
+ describe "::some_method" do
65
+ let_m
66
+ it { expect(m).to eq :some_method }
67
+ end
68
+
69
+ describe "#[]" do
70
+ let_m
71
+ it { expect(m).to eq :[] }
72
+ end
73
+
74
+ describe ".[]" do
75
+ let_m
76
+ it { expect(m).to eq :[] }
77
+ end
78
+
79
+ describe "::[]" do
80
+ let_m
81
+ it { expect(m).to eq :[] }
82
+ end
83
+
84
+ describe "GET some_action" do
85
+ let_m
86
+ it { expect(m).to eq :some_action }
87
+ end
88
+
89
+ describe "POST some_action" do
90
+ let_m
91
+ it { expect(m).to eq :some_action }
92
+ end
93
+
94
+ describe "PUT some_action" do
95
+ let_m
96
+ it { expect(m).to eq :some_action }
97
+ end
98
+
99
+ describe "DELETE some_action" do
100
+ let_m
101
+ it { expect(m).to eq :some_action }
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,46 @@
1
+
2
+ RSpec.describe ".use_custom_let" do
3
+ use_custom_let(:let_a, :attrs)
4
+
5
+ describe "straight usage" do
6
+ describe "attrs" do
7
+ let_a(:name) { "Joe" }
8
+ let_a(:age) { 25 }
9
+ let(:gender) { :male }
10
+ it do
11
+ expect(name).to eq "Joe"
12
+ expect(age).to eq 25
13
+ expect(attrs).to eq(name: "Joe", age: 25)
14
+ expect(attrs(include: [:gender])).to eq(name: "Joe", age: 25, gender: :male)
15
+ end
16
+ end
17
+ end
18
+
19
+ describe "declarative (no block) usage" do
20
+ let_a(:name)
21
+
22
+ subject { attrs }
23
+
24
+ context "when no other `let` value" do
25
+ it { is_expected.to eq({}) }
26
+ end
27
+
28
+ context "when `let`" do
29
+ let(:name) { "Joe" }
30
+ it { is_expected.to eq(name: "Joe") }
31
+ end
32
+
33
+ context "when `let_a`" do
34
+ let_a(:name) { "Joe" }
35
+ it { is_expected.to eq(name: "Joe") }
36
+ end
37
+
38
+ context_when name: "Joe" do
39
+ context_when name: "Moe" do
40
+ it { is_expected.to eq(name: "Moe") }
41
+ end
42
+
43
+ it { is_expected.to eq(name: "Joe") }
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,6 @@
1
+
2
+ # Self.
3
+ require "rails_dt"
4
+
5
+ # Load support files. Sorted alphabetically for greater control.
6
+ Dir[File.expand_path("support/**/*.rb", __dir__)].sort.each { |fn| require fn }
@@ -0,0 +1,23 @@
1
+
2
+ #
3
+ # Convenience methods to extend RSpec metalanguage.
4
+ # This file must be loaded before other support files.
5
+ #
6
+
7
+ module Kernel
8
+ def extend_describe(&block)
9
+ raise ArgumentError, "Code block must be given" unless block
10
+
11
+ ::RSpec.configure do |config|
12
+ config.extend Module.new(&block)
13
+ end
14
+ end
15
+
16
+ def extend_it(&block)
17
+ raise ArgumentError, "Code block must be given" unless block
18
+
19
+ ::RSpec.configure do |config|
20
+ config.include Module.new(&block)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+
2
+ #
3
+ # Method alias matcher.
4
+ #
5
+ # describe User do
6
+ # it { is_expected.to alias_method(:admin?, :is_admin) }
7
+ # end
8
+ #
9
+ # Originally from: https://gist.github.com/1950961, but heavily reworked consistency-wise.
10
+ #
11
+
12
+ RSpec::Matchers.define :alias_method do |new_name, old_name|
13
+ match do |subject|
14
+ expect(subject.method(new_name)).to eq subject.method(old_name)
15
+ end
16
+
17
+ description do
18
+ "have #{new_name.inspect} aliased to #{old_name.inspect}"
19
+ end
20
+ end
@@ -0,0 +1,39 @@
1
+
2
+ extend_describe do
3
+ # Create a `context "when ..."`, with a set of let variables defined.
4
+ #
5
+ # context_when a: 1, x: "y" do
6
+ # it { expect(a).to eq 1 } # Success.
7
+ # it { expect(x).to eq "y" } # Success.
8
+ # end
9
+ #
10
+ # , is identical to:
11
+ #
12
+ # context "when {a: 1, x: \"y\"}" do
13
+ # let(:a) { 1 }
14
+ # let(:x) { "y" }
15
+ # ...
16
+ #
17
+ # @param h [Hash]
18
+ # @param format_proc [Proc]
19
+ # @return [void]
20
+ def context_when(h, format_proc: context_when_default_format_proc, &block)
21
+ context format_proc[h] do
22
+ h.each do |k, v|
23
+ let(k) { v }
24
+ end
25
+ class_eval(&block)
26
+ end
27
+ end
28
+
29
+ # Default <tt>format_proc</tt> for {.context_when}.
30
+ # @return [Proc]
31
+ # @see .context_when
32
+ def context_when_default_format_proc
33
+ ->(h) do
34
+ # Primitive readability hack. Might screw string values, too.
35
+ inspected = h.inspect.gsub(/:(\w+)=>/, "\\1: ")
36
+ "when #{inspected}"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+
2
+ extend_describe do
3
+ # Add a variable, named <tt>m</tt> by default, containing the symbolized method name from the
4
+ # description. Example:
5
+ #
6
+ # describe "#some_method" do
7
+ # let_m
8
+ #
9
+ # , is identical to:
10
+ #
11
+ # describe "#some_method" do
12
+ # let(:m) { :some_method }
13
+ # def self.m; :some_method; end
14
+ #
15
+ # @param let [Symbol] Name of the variable to create.
16
+ # @return [void]
17
+ def let_m(let = :m)
18
+ if (mat = (description = self.description).match(/^(?:(?:#|\.|::)(\w+(?:\?|!|)|\[\])|(?:DELETE|GET|PUT|POST) (\w+))$/))
19
+ s = mat[1] || mat[2]
20
+ sym = s.to_sym
21
+ let(let) { sym }
22
+ define_singleton_method(let) { sym }
23
+ else
24
+ raise ArgumentError, "Unknown description format: #{description.inspect}"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,80 @@
1
+
2
+ extend_describe do
3
+ # Define methods to manage of <tt>let</tt> variables which act as a distinct subset.
4
+ #
5
+ # RSpec.describe SomeKlass do
6
+ # use_custom_let(:let_a, :attrs) # (1)
7
+ # use_custom_let(:let_p, :params) # (2)
8
+ # ...
9
+ #
10
+ # In above examples, (1) provides our suite with:
11
+ #
12
+ # def self.let_a(let, &block)
13
+ # def attrs(include: [])
14
+ #
15
+ # , thus this now becomes possible:
16
+ #
17
+ # describe "attrs" do
18
+ # let_a(:name) { "Joe" }
19
+ # let_a(:age) { 25 }
20
+ # let(:gender) { :male }
21
+ # it do
22
+ # expect(name).to eq "Joe"
23
+ # expect(age).to eq 25
24
+ # expect(attrs).to eq(name: "Joe", age: 25)
25
+ # expect(attrs(include: [:gender])).to eq(name: "Joe", age: 25, gender: :male)
26
+ # end
27
+ # end
28
+ #
29
+ # By not providing a block it's possible to <b>declare</b> a custom <tt>let</tt> variable
30
+ # and be able to redefine it later via regular <tt>let</tt>. This will work:
31
+ #
32
+ # describe "declarative (no block) usage" do
33
+ # let_a(:name)
34
+ #
35
+ # subject { attrs }
36
+ #
37
+ # context "when no other `let` value" do
38
+ # it { is_expected.to eq({}) }
39
+ # end
40
+ #
41
+ # context "when `let`" do
42
+ # let(:name) { "Joe" }
43
+ # it { is_expected.to eq(name: "Joe") }
44
+ # end
45
+ # end
46
+ #
47
+ # NOTE: At the moment the feature only works if <tt>use_custom_let</tt> is invoked from a
48
+ # top-level (<tt>RSpec.describe</tt>) context. Correct usage in sub-context is yet not possible.
49
+ def use_custom_let(let_method, collection_method)
50
+ class_eval %{
51
+ def self.#{let_method}(let, &block)
52
+ #{let_method}_keys << let
53
+ let(let, &block) if block
54
+ end
55
+
56
+ def self.#{let_method}_keys
57
+ @#{let_method}_keys ||= []
58
+ end
59
+
60
+ # OPTIMIZE: Consider removing `include:` altogether as we've got declarative mode now.
61
+ def #{collection_method}(include: [])
62
+ # NOTE: We don't store computation in a @variable since we have an argument. The result
63
+ # may vary.
64
+ begin
65
+ keys, klass = include, self.class
66
+ begin
67
+ keys += klass.#{let_method}_keys
68
+ end while (klass = klass.superclass) < RSpec::Core::ExampleGroup
69
+ # NOTE: `< RSpec::Core::ExampleGroup` is probably the reason why we can't use this in
70
+ # sub-contexts. The need for such use is highly questionable since this feature in
71
+ # effect extends RSpec syntax.
72
+
73
+ {}.tap do |_|
74
+ keys.uniq.each { |k| begin; _[k] = public_send(k); rescue NoMethodError; end }
75
+ end
76
+ end
77
+ end
78
+ } # class_eval
79
+ end
80
+ end
metadata CHANGED
@@ -1,77 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rails_dt
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Alex Fortuna
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-07-13 00:00:00 +04:00
14
- default_executable:
11
+ date: 2018-03-23 00:00:00.000000000 Z
15
12
  dependencies: []
16
-
17
- description: Rails Debug Toolkit
18
- email: alex.r@askit.org
13
+ description:
14
+ email:
15
+ - fortunadze@gmail.com
19
16
  executables: []
20
-
21
17
  extensions: []
22
-
23
- extra_rdoc_files:
24
- - README.html
25
- - README.md
26
- files:
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".yardopts"
22
+ - Gemfile
27
23
  - MIT-LICENSE
28
- - README.html
29
24
  - README.md
30
- - Rakefile
31
- - VERSION.yml
32
- - generators/rails_dt/USAGE
33
- - generators/rails_dt/WARNING
34
- - generators/rails_dt/rails_dt_generator.rb
35
- - generators/rails_dt/templates/INSTALL
36
- - generators/rails_dt/templates/dt.css
37
- - generators/rails_dt/templates/dt.rb
38
- - init.rb
39
25
  - lib/dt.rb
40
- - lib/dt/action_controller_extensions.rb
41
- - lib/generators/rails_dt/USAGE
42
- - lib/generators/rails_dt/rails_dt_generator.rb
43
- - lib/generators/rails_dt/templates/INSTALL
44
- - lib/generators/rails_dt/templates/dt.css
45
- - lib/generators/rails_dt/templates/dt.rb
26
+ - lib/dt/config.rb
27
+ - lib/dt/instance.rb
46
28
  - lib/rails_dt.rb
29
+ - lib/rails_dt/version.rb
47
30
  - rails_dt.gemspec
48
- has_rdoc: true
31
+ - spec/lib/dt/config_spec.rb
32
+ - spec/lib/dt/instance_spec.rb
33
+ - spec/lib/dt_spec.rb
34
+ - spec/lib/rails_dt_spec.rb
35
+ - spec/lib/spec/alias_method_matcher_spec.rb
36
+ - spec/lib/spec/context_when_spec.rb
37
+ - spec/lib/spec/let_m_spec.rb
38
+ - spec/lib/spec/use_custom_let_spec.rb
39
+ - spec/spec_helper.rb
40
+ - spec/support/00extend_x.rb
41
+ - spec/support/alias_method_matcher.rb
42
+ - spec/support/context_when.rb
43
+ - spec/support/let_m.rb
44
+ - spec/support/use_custom_let.rb
49
45
  homepage: http://github.com/dadooda/rails_dt
50
46
  licenses: []
51
-
47
+ metadata: {}
52
48
  post_install_message:
53
49
  rdoc_options: []
54
-
55
- require_paths:
50
+ require_paths:
56
51
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
60
54
  - - ">="
61
- - !ruby/object:Gem::Version
62
- version: "0"
63
- required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
- requirements:
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
66
59
  - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
69
62
  requirements: []
70
-
71
63
  rubyforge_project:
72
- rubygems_version: 1.6.2
64
+ rubygems_version: 2.5.2
73
65
  signing_key:
74
- specification_version: 3
75
- summary: Rails Debug Toolkit
66
+ specification_version: 4
67
+ summary: Ruby/Rails debug toolkit
76
68
  test_files: []
77
-