Skip to content

Commit

Permalink
write some file change and deletion tests for better data coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed May 29, 2013
1 parent b8b48af commit 86cd626
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,3 +17,4 @@ tmp
Makefile
.mm-pid-*
.idea
*.sublime-workspace
6 changes: 0 additions & 6 deletions .simplecov

This file was deleted.

26 changes: 25 additions & 1 deletion middleman-core/features/data.feature
Expand Up @@ -5,11 +5,35 @@ Feature: Local Data API
Given the Server is running at "basic-data-app"
When I go to "/data.html"
Then I should see "One:Two"
When the file "data/test.yml" has the contents
"""
-
title: "Three"
-
title: "Four"
"""
When I go to "/data.html"
Then I should see "Three:Four"
When the file "data/test.yml" is removed
When I go to "/data.html"
Then I should see "No Test Data"

Scenario: Rendering json
Given the Server is running at "basic-data-app"
When I go to "/data3.html"
Then I should see "One:Two"
When the file "data/test2.json" has the contents
"""
[
{ "title": "Three" },
{ "title": "Four" }
]
"""
When I go to "/data3.html"
Then I should see "Three:Four"
When the file "data/test2.json" is removed
When I go to "/data3.html"
Then I should see "No Test Data"

Scenario: Using data in config.rb
Given the Server is running at "data-app"
Expand All @@ -26,4 +50,4 @@ Feature: Local Data API
When I go to "/test.html"
Then I should see "title1:Hello"
Then I should see "title2:More"
Then I should see "title3:Stuff"
Then I should see "title3:Stuff"
6 changes: 5 additions & 1 deletion middleman-core/fixtures/basic-data-app/source/data.html.erb
@@ -1 +1,5 @@
<%= data.test.map { |r| r.title }.join(":") %>
<% if data.respond_to?(:test) %>
<%= data.test.map { |r| r.title }.join(":") %>
<% else %>
No Test Data
<% end %>
6 changes: 5 additions & 1 deletion middleman-core/fixtures/basic-data-app/source/data3.html.erb
@@ -1 +1,5 @@
<%= data.test2.map { |r| r.title }.join(":") %>
<% if data.respond_to?(:test2) %>
<%= data.test2.map { |r| r.title }.join(":") %>
<% else %>
No Test Data
<% end %>
2 changes: 1 addition & 1 deletion middleman-core/lib/middleman-core/application.rb
Expand Up @@ -170,7 +170,7 @@ def initialize(&block)
# @private
# @return [Middleman::Util::Cache] The cache
def self.cache
@_cache ||= ::Middleman::Util::Cache.new
@_cache ||= ::Tilt::Cache.new
end
delegate :cache, :to => :"self.class"

Expand Down
57 changes: 0 additions & 57 deletions middleman-core/lib/middleman-core/util.rb
Expand Up @@ -146,62 +146,5 @@ def self.all_files_under(*paths)
end
end.flatten.compact
end

# Simple shared cache implementation
class Cache
# Initialize
def initialize
self.clear
end

# Either get the cached key or save the contents of the block
#
# @param key Anything Hash can use as a key
def fetch(*key)
@cache[key] ||= yield
end

# Whether the key is in the cache
#
# @param key Anything Hash can use as a key
# @return [Boolean]
def has_key?(key)
@cache.has_key?(key)
end

# Get a specific key
#
# @param key Anything Hash can use as a key
def get(key)
@cache[key]
end

# Array of keys
# @return [Array]
def keys
@cache.keys
end

# Clear the entire cache
# @return [void]
def clear
@cache = {}
end

# Set a specific key
#
# @param key Anything Hash can use as a key
# @param value Cached value
# @return [void]
def set(key, value)
@cache[key] = value
end

# Remove a specific key
# @param key Anything Hash can use as a key
def remove(*key)
@cache.delete(key)
end
end
end
end
16 changes: 16 additions & 0 deletions middleman.sublime-project
@@ -0,0 +1,16 @@
{
"folders":
[
{
"path": ".",
"folder_exclude_patterns": [".sass-cache", ".bundle", "tmp", "coverage"],
"file_exclude_patterns": ["*.sublime-workspace"]
}
],

"settings":
{
"tab_size": 2,
"translate_tabs_to_spaces": true
}
}

0 comments on commit 86cd626

Please sign in to comment.