great_pretender 0.1.1 → 0.1.2

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: 83426688dbe661c6888971ba60756bd22a22d8e9
4
- data.tar.gz: 609888f148e55a50216994b642adb78527f8f56f
3
+ metadata.gz: be13699344821526b0f5bb5bd0be76401d32b24f
4
+ data.tar.gz: d7f7f6e97097818c566be9ab78cd6a7226f7fa12
5
5
  SHA512:
6
- metadata.gz: 3a87473df668fc6b002039e804e07aa0dfd3d93ed8e60aa671ca4077439e13795c0baa92409de6dec5d7b8c8dd3fa29dbc0a6c24e8afe058b44d88e203a18dc5
7
- data.tar.gz: 416e2559c885fe04eb3a55a109e57b38a93944886dac8a1f8c8a734912b38654c263d6be76b03ada883f15d9d475f50f9c12d393c96f31449603674cbcd0c87c
6
+ metadata.gz: 6d4a07e77ef31ff590cda5c8fe437a1ed28d894424b0d95309bdf870903264d05f061a6c8e81a1409da48930117d26ef73898e96c74cc1d2e658d8befdfb6c87
7
+ data.tar.gz: a4c3842bd70ab69c3953223b79cf9723c1814e6c316ccc81dfcd47a849d13b45354f79fe9aa38f5f35015ae7c17ba4e4cbb6aee8b2a3355c50e34a809731efc7
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .DS_Store
data/Gemfile CHANGED
@@ -2,4 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in great_pretender.gemspec
4
4
  gemspec
5
- gem "rspec-rails"
5
+
6
+ group :test do
7
+ gem "rspec-rails"
8
+ gem "codeclimate-test-reporter", require: false
9
+ gem "simplecov", require: false
10
+ end
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Code Climate](https://codeclimate.com/github/BackForty/great_pretender/badges/gpa.svg)](https://codeclimate.com/github/BackForty/great_pretender) [![Test Coverage](https://codeclimate.com/github/BackForty/great_pretender/badges/coverage.svg)](https://codeclimate.com/github/BackForty/great_pretender)
2
+
1
3
  # Great Pretender
2
4
 
3
5
  **Ridiculously easy-to-use Rails mockups for those enlightened individuals who design in-browser.**
@@ -18,6 +18,7 @@ module GreatPretender
18
18
  end
19
19
  end
20
20
  end
21
+
21
22
  end
22
23
 
23
24
  class MissingPathHelperError < StandardError
@@ -26,4 +27,5 @@ module GreatPretender
26
27
  @original_error = error
27
28
  end
28
29
  end
30
+
29
31
  end
@@ -5,7 +5,6 @@ module GreatPretender
5
5
  module Controller
6
6
 
7
7
  def self.included(base)
8
- base.helper_method :mockup
9
8
  base.helper_method :mockups
10
9
  base.helper_method :mockup_root
11
10
  base.helper GreatPretender::MockupsHelper
@@ -18,7 +18,7 @@ module GreatPretender
18
18
  if slug =~ /^_/
19
19
  name << ' (partial)'
20
20
  end
21
- @name = name
21
+ @name = name.strip
22
22
  end
23
23
 
24
24
  def updated_at
@@ -14,15 +14,7 @@ module GreatPretender
14
14
  return @mockups if defined? @mockups
15
15
  mockups = []
16
16
  @view_paths.each do |view_path|
17
- root = view_path.join(GreatPretender.config.view_path)
18
- templates = Dir[root.join("**/*.#{extensions}")]
19
- templates.each do |path|
20
- mockup = Mockup.new(path)
21
- mockup.slug = slug_for(root, path)
22
- mockup.layout = layout_for(mockup.slug)
23
- mockup.template = template_for(view_path, root, mockup.slug)
24
- mockups.push(mockup)
25
- end
17
+ mockups.push(*mockups_for(view_path))
26
18
  end
27
19
  @mockups = mockups
28
20
  end
@@ -69,6 +61,22 @@ module GreatPretender
69
61
  end
70
62
  end
71
63
 
64
+ def mockup_for(view_path, root, path)
65
+ mockup = Mockup.new(path)
66
+ mockup.slug = slug_for(root, path)
67
+ mockup.layout = layout_for(mockup.slug)
68
+ mockup.template = template_for(view_path, root, mockup.slug)
69
+ mockup
70
+ end
71
+
72
+ def mockups_for(view_path)
73
+ root = view_path.join(GreatPretender.config.view_path)
74
+ templates = Dir[root.join("**/*.#{extensions}")]
75
+ templates.map do |path|
76
+ mockup_for(view_path, root, path)
77
+ end
78
+ end
79
+
72
80
  def slug_for(root, path)
73
81
  slug = path.to_s.gsub(%r{^#{root.to_s}/}, '')
74
82
  while (ext = File.extname(slug)).length > 0
@@ -47,9 +47,10 @@ module GreatPretender
47
47
  @mockup.slug.split("/").each do |pretender_name|
48
48
  # Given a mockup named something like 'social_contents',
49
49
  # support pretenders named 'SocialContentsPretender' AND 'SocialContentPretender'
50
- first_class = pretender_name.classify
51
- second_class = pretender_name.split("_").map(&:titleize).join
52
- [first_class, second_class].uniq.each do |class_name|
50
+ singular_class = pretender_name.classify
51
+ plural_class = singular_class.pluralize
52
+
53
+ [singular_class, plural_class].each do |class_name|
53
54
  if instance = load_pretender(class_name)
54
55
  pretenders.push(instance)
55
56
  end
@@ -1,3 +1,3 @@
1
1
  module GreatPretender
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+ #require 'rspec/rails'
3
+ #require 'great_pretender/mockups_controller'
4
+
5
+ #describe GreatPretender::MockupsController do
6
+
7
+ #end
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  module GreatPretender; end
2
4
 
3
5
  describe GreatPretender do
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  require 'great_pretender/mockup_locator'
2
4
  require 'pathname'
3
5
  require_relative '../../support/mockup_helpers'
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  require 'great_pretender/mockup'
2
4
  require_relative '../../support/mockup_helpers'
3
5
 
@@ -6,9 +8,16 @@ describe GreatPretender::Mockup do
6
8
  include MockupHelpers
7
9
 
8
10
  let(:mockup) { mockup_locator.mockups.find {|m| m.slug =~ /admin/ } }
11
+ let(:partial) { mockup_locator.mockups.find {|m| m.slug =~ /^_/ } }
12
+
13
+ context ".name" do
14
+ it "returns a human-readable name from its slug" do
15
+ expect(mockup.name).to eq("Admin > Index")
16
+ end
9
17
 
10
- it "returns a human-readable name from its slug" do
11
- expect(mockup.name).to eq("Admin > Index")
18
+ it "marks a partial as such" do
19
+ expect(partial.name).to eq("Partial (partial)")
20
+ end
12
21
  end
13
22
 
14
23
  context ".to_param" do
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  require 'great_pretender/pretender'
2
4
  require 'ostruct'
3
5
 
@@ -5,12 +7,26 @@ class PrefixSlugPretender
5
7
  def say_hello
6
8
  "Hello, guest!"
7
9
  end
10
+
11
+ def name
12
+ "Flip"
13
+ end
8
14
  end
9
15
 
10
- class TestSlugPretender
16
+ class TestSlugsPretender
17
+ attr_reader :mockup
18
+
19
+ def initialize(mockup)
20
+ @mockup = mockup
21
+ end
22
+
11
23
  def ohai
12
24
  "ohai"
13
25
  end
26
+
27
+ def name
28
+ "Avery"
29
+ end
14
30
  end
15
31
 
16
32
  describe GreatPretender::Pretender do
@@ -30,4 +46,21 @@ describe GreatPretender::Pretender do
30
46
  expect(recipient.say_hello).to eq("Hello, guest!")
31
47
  end
32
48
 
49
+ it "delegates methods to the most specific responder" do
50
+ expect(recipient.name).to eq("Avery")
51
+ end
52
+
53
+ it "passes the mockup to pretenders that accept an initialization argument" do
54
+ expect(TestSlugsPretender).to receive(:new).with(mockup)
55
+ recipient
56
+ end
57
+
58
+ it "correctly calls super when a method doesn't exist" do
59
+ expect(-> { recipient.foobar }).to raise_error(NoMethodError)
60
+ end
61
+
62
+ it "quietly flunks mockups without pretenders" do
63
+ pretenderless_mockup = OpenStruct.new(slug: "no_pretender_mockup")
64
+ expect(-> { GreatPretender::Pretender.new(pretenderless_mockup) } ).not_to raise_error
65
+ end
33
66
  end
@@ -0,0 +1,9 @@
1
+ if ENV["CODECLIMATE_REPO_TOKEN"]
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
+ else
5
+ require "simplecov"
6
+ SimpleCov.start do
7
+ add_filter 'spec'
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ require "ostruct"
2
+
1
3
  module MockupHelpers
2
4
  def self.included(base)
3
5
  base.class_eval do
@@ -5,7 +7,8 @@ module MockupHelpers
5
7
  let(:paths) do
6
8
  [
7
9
  Pathname.new("spec/fixtures/view_path_a").expand_path,
8
- Stub.new("spec/fixtures/view_path_b")
10
+ OpenStruct.new(to_path: "spec/fixtures/view_path_b"),
11
+ OpenStruct.new(to_s: "spec/fixtures/view_path_c")
9
12
  ]
10
13
  end
11
14
 
@@ -13,14 +16,4 @@ module MockupHelpers
13
16
 
14
17
  end
15
18
  end
16
-
17
- class Stub
18
- def initialize(path)
19
- @path = path
20
- end
21
-
22
- def to_path
23
- @path.to_s
24
- end
25
- end
26
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: great_pretender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flip Sasser
@@ -67,6 +67,7 @@ files:
67
67
  - lib/great_pretender/mockup_locator.rb
68
68
  - lib/great_pretender/pretender.rb
69
69
  - lib/great_pretender/version.rb
70
+ - spec/controllers/great_pretender/mockups_controller_spec.rb
70
71
  - spec/fixtures/view_path_a/.DS_Store
71
72
  - spec/fixtures/view_path_a/layouts/admin.html.slim
72
73
  - spec/fixtures/view_path_a/mockups/_partial.haml
@@ -78,6 +79,7 @@ files:
78
79
  - spec/lib/great_pretender/mockup_locator_spec.rb
79
80
  - spec/lib/great_pretender/mockup_spec.rb
80
81
  - spec/lib/great_pretender/pretender_spec.rb
82
+ - spec/spec_helper.rb
81
83
  - spec/support/mockup_helpers.rb
82
84
  homepage: https://github.com/BackForty/great_pretender
83
85
  licenses:
@@ -105,6 +107,7 @@ specification_version: 4
105
107
  summary: Ridiculously easy-to-use Rails mockups for those enlightened individuals
106
108
  who design in-browser
107
109
  test_files:
110
+ - spec/controllers/great_pretender/mockups_controller_spec.rb
108
111
  - spec/fixtures/view_path_a/.DS_Store
109
112
  - spec/fixtures/view_path_a/layouts/admin.html.slim
110
113
  - spec/fixtures/view_path_a/mockups/_partial.haml
@@ -116,4 +119,5 @@ test_files:
116
119
  - spec/lib/great_pretender/mockup_locator_spec.rb
117
120
  - spec/lib/great_pretender/mockup_spec.rb
118
121
  - spec/lib/great_pretender/pretender_spec.rb
122
+ - spec/spec_helper.rb
119
123
  - spec/support/mockup_helpers.rb