Module: Noumenon::Spec::ThemeHelpers
- Defined in:
- lib/noumenon/spec/theme_helpers.rb
Overview
Methods which can be used in RSpec based tests to create and use themes that will be recreated on each test run.
Instance Method Summary collapse
-
#create_theme(description = {}) ⇒ Noumenon::Theme?
Create a new theme directory at #theme_path.
-
#theme_path ⇒ String
The path to the current theme.
-
#with_temporary_theme(description = {}) ⇒ Object
Creates a theme with the provided description, runs the block, and then deletes the theme again.
Instance Method Details
#create_theme(description = {}) ⇒ Noumenon::Theme?
Create a new theme directory at #theme_path.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/noumenon/spec/theme_helpers.rb', line 23 def create_theme(description = {}) FileUtils.mkdir_p theme_path FileUtils.mkdir_p File.join(theme_path, "templates") FileUtils.mkdir_p File.join(theme_path, "layouts") FileUtils.mkdir_p File.join(theme_path, "assets") if description File.open(File.join(theme_path, "theme.yml"), "w") do |f| f.print description.to_yaml end return Noumenon::Theme.load(theme_path) end end |
#theme_path ⇒ String
The path to the current theme.
13 14 15 |
# File 'lib/noumenon/spec/theme_helpers.rb', line 13 def theme_path File.("../../../../tmp/example_theme", __FILE__) end |
#with_temporary_theme(description = {}) ⇒ Object
Creates a theme with the provided description, runs the block, and then deletes the theme again.
Useful in RSpec around blocks:
57 58 59 60 61 62 63 |
# File 'lib/noumenon/spec/theme_helpers.rb', line 57 def with_temporary_theme(description = {}) create_theme(description) yield FileUtils.rm_r theme_path end |