trundle 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ RSpec.describe Trundle::Key do
2
+ describe '#camelize' do
3
+ it 'does not change a lower case string' do
4
+ expect(described_class.new('version').camelize).to eq('version')
5
+ end
6
+
7
+ it 'does not change a camelized string' do
8
+ expect(described_class.new('creatorIdentifier').camelize).to eq('creatorIdentifier')
9
+ end
10
+
11
+ it 'does not change a camelized string with URL at the end' do
12
+ expect(described_class.new('sourceURL').camelize).to eq('sourceURL')
13
+ end
14
+
15
+ it 'handles a multi word string' do
16
+ expect(described_class.new('creator_identifier').camelize).to eq('creatorIdentifier')
17
+ end
18
+
19
+ it 'handles a string with URL at the end' do
20
+ expect(described_class.new('source_url').camelize).to eq('sourceURL')
21
+ end
22
+
23
+ it 'handles a string with URL in the middle' do
24
+ expect(described_class.new('source_url_original').camelize).to eq('sourceUrlOriginal')
25
+ end
26
+ end
27
+
28
+ describe '#underscore' do
29
+ it 'does not change a lower case string' do
30
+ expect(described_class.new('version').underscore).to eq('version')
31
+ end
32
+
33
+ it 'does not change an underscored string' do
34
+ expect(described_class.new('creator_identifier').underscore).to eq('creator_identifier')
35
+ end
36
+
37
+ it 'does not change an underscored string with URL at the end' do
38
+ expect(described_class.new('source_url').underscore).to eq('source_url')
39
+ end
40
+
41
+ it 'handles a multi word string' do
42
+ expect(described_class.new('creatorIdentifier').underscore).to eq('creator_identifier')
43
+ end
44
+
45
+ it 'handles a string with URL at the end' do
46
+ expect(described_class.new('sourceURL').underscore).to eq('source_url')
47
+ end
48
+
49
+ it 'handles a string with URL in the middle' do
50
+ expect(described_class.new('sourceUrlOriginal').underscore).to eq('source_url_original')
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,21 @@
1
+ RSpec.describe Trundle::NamespaceList do
2
+ let(:namespace_list) { described_class.new }
3
+
4
+ it 'does not include a namespace when it is empty' do
5
+ expect(namespace_list.include?(:monkey_island)).to be false
6
+ end
7
+
8
+ context 'a namespace has been set' do
9
+ before do
10
+ namespace_list.monkey_island('io.monkeyisland')
11
+ end
12
+
13
+ it 'includes the namespace' do
14
+ expect(namespace_list.include?(:monkey_island)).to be true
15
+ end
16
+
17
+ it 'returns the key' do
18
+ expect(namespace_list.key(:monkey_island)).to eq('io.monkeyisland')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,87 @@
1
+ RSpec.describe Trundle::TextBundle do
2
+ describe 'Info' do
3
+ let(:text_bundle) { described_class.new(text_bundle_path) }
4
+
5
+ describe 'Reading' do
6
+ let(:text_bundle_path) { 'spec/samples/offical-v2.textbundle' }
7
+
8
+ it 'is transient' do
9
+ expect(text_bundle).to be_transient
10
+ end
11
+
12
+ it 'reads the type' do
13
+ expect(text_bundle.type).to eq('net.daringfireball.markdown')
14
+ end
15
+
16
+ it 'reads the version' do
17
+ expect(text_bundle.version).to eq(2)
18
+ end
19
+
20
+ it 'reads the creator URL' do
21
+ expect(text_bundle.creator_url).to eq('file:///Applications/Example.app/')
22
+ end
23
+
24
+ it 'reads the creator identifier' do
25
+ expect(text_bundle.creator_identifier).to eq('com.example.editor')
26
+ end
27
+
28
+ it 'reads the source URL' do
29
+ expect(text_bundle.source_url).to eq('file:///Users/johndoe/Documents/myfile.markdown/')
30
+ end
31
+ end
32
+
33
+ describe 'Writing' do
34
+ let(:text_bundle_path) { 'spec/tmp/example.textbundle' }
35
+
36
+ it 'writes the transient setting' do
37
+ text_bundle.transient = false
38
+ text_bundle.close
39
+
40
+ expect(described_class.new(text_bundle_path)).not_to be_transient
41
+ end
42
+
43
+ it 'writes the version' do
44
+ text_bundle.version = 2
45
+ text_bundle.close
46
+
47
+ expect(described_class.new(text_bundle_path).version).to eq(2)
48
+ end
49
+
50
+ it 'writes the creator URL' do
51
+ text_bundle.creator_url = 'file:///Applications/Example.app/'
52
+ text_bundle.close
53
+
54
+ expect(described_class.new(text_bundle_path).creator_url).to eq('file:///Applications/Example.app/')
55
+ end
56
+
57
+ it 'writes the creator identifier' do
58
+ text_bundle.creator_identifier = 'com.example.editor'
59
+ text_bundle.close
60
+
61
+ expect(described_class.new(text_bundle_path).creator_identifier).to eq('com.example.editor')
62
+ end
63
+
64
+ it 'writes the source URL' do
65
+ text_bundle.source_url = 'file:///Users/johndoe/Documents/myfile.markdown/'
66
+ text_bundle.close
67
+
68
+ expect(described_class.new(text_bundle_path).source_url).to eq('file:///Users/johndoe/Documents/myfile.markdown/')
69
+ end
70
+
71
+ it 'writes the type' do
72
+ text_bundle.type = 'net.daringfireball.markdown'
73
+ text_bundle.close
74
+
75
+ expect(described_class.new(text_bundle_path).type).to eq('net.daringfireball.markdown')
76
+ end
77
+
78
+ describe '#transient=' do
79
+ it 'raises an error when the value is not a boolean' do
80
+ [[], '', nil, {}].each do |value|
81
+ expect{ text_bundle.transient = value }.to raise_error(ArgumentError, 'transient must be a boolean')
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,67 @@
1
+ RSpec.describe Trundle::TextBundle do
2
+ describe 'Namespaces' do
3
+ let(:text_bundle) { described_class.new(text_bundle_path) }
4
+
5
+ before do
6
+ Trundle.configure do |config|
7
+ config.namespaces do
8
+ monkey_island 'io.monkeyisland'
9
+ scabb_island 'io.scabbisland'
10
+ end
11
+ end
12
+ end
13
+
14
+ describe 'Reading' do
15
+ let(:text_bundle_path) { 'spec/samples/namespaces.textbundle' }
16
+
17
+ it 'always returns the same namespace object' do
18
+ expect(text_bundle.monkey_island).to equal(text_bundle.monkey_island)
19
+ expect(text_bundle.scabb_island).not_to equal(text_bundle.monkey_island)
20
+ end
21
+
22
+ it 'reads attributes from the namespaces' do
23
+ expect(text_bundle.monkey_island.version).to eq(1)
24
+ expect(text_bundle.scabb_island.version).to eq(6)
25
+ end
26
+
27
+ it 'reads underscored attributes' do
28
+ expect(text_bundle.monkey_island.local_castaway).to eq('Herman Toothrot')
29
+ end
30
+
31
+ it 'raises an error if the namespace has not been defined' do
32
+ message = <<-STRING.gsub(/^ {10}/, '').strip
33
+ The namespace "melee_island" is not defined!
34
+
35
+ Add it to your config using:
36
+
37
+ Trundle.configure do |config|
38
+ config.namespaces do
39
+ melee_island 'unique.namespace.key'
40
+ end
41
+ end
42
+ STRING
43
+ expect{ text_bundle.melee_island }.to raise_error(Trundle::NamespaceNotDefined, message)
44
+ end
45
+ end
46
+
47
+ describe 'Writing' do
48
+ let(:text_bundle_path) { 'spec/tmp/example.textbundle' }
49
+
50
+ it 'writes a value' do
51
+ text_bundle.monkey_island.version = 9
52
+ text_bundle.close
53
+
54
+ fresh_bundle = described_class.new(text_bundle_path)
55
+ expect(fresh_bundle.monkey_island.version).to eq(9)
56
+ end
57
+
58
+ it 'writes a value to an underscored attribute' do
59
+ text_bundle.monkey_island.local_castaway = 'Herman Toothrot'
60
+ text_bundle.close
61
+
62
+ fresh_bundle = described_class.new(text_bundle_path)
63
+ expect(fresh_bundle.monkey_island.local_castaway).to eq('Herman Toothrot')
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,26 @@
1
+ RSpec.describe Trundle::TextBundle do
2
+ describe 'Text' do
3
+ let(:text_bundle) { described_class.new(text_bundle_path) }
4
+
5
+ describe 'Reading' do
6
+ let(:content) { File.read(text_bundle_path + '/text.markdown') }
7
+ let(:text_bundle_path) { 'spec/samples/offical-v2.textbundle' }
8
+
9
+ it 'reads the text content' do
10
+ expect(text_bundle.text).to eq(content)
11
+ end
12
+ end
13
+
14
+ describe 'Writing' do
15
+ let(:text) { 'Guybrush Threepwood is a mighty pirate. Ish.' }
16
+ let(:text_bundle_path) { 'spec/tmp/example.textbundle' }
17
+
18
+ it 'writes the text content' do
19
+ text_bundle.text = text
20
+ text_bundle.close
21
+
22
+ expect(described_class.new(text_bundle_path).text).to eq(text)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,81 @@
1
+ RSpec.describe Trundle::TextBundle do
2
+ let(:text_bundle) { described_class.new(text_bundle_path) }
3
+
4
+ describe 'Reading a TextBundle' do
5
+ let(:text_bundle_path) { 'spec/samples/offical-v2.textbundle' }
6
+
7
+ it 'exists' do
8
+ expect(text_bundle).to exist
9
+ end
10
+
11
+ context 'when configuration options are set' do
12
+ let(:text_bundle_path) { 'spec/samples/blank.textbundle' }
13
+
14
+ before do
15
+ Trundle.configure do |config|
16
+ config.version = 3
17
+ end
18
+ end
19
+
20
+ it 'does not merge in the config' do
21
+ expect(text_bundle.version).not_to eq(3)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe 'Writing a TextBundle' do
27
+ let(:text_bundle_path) { 'spec/tmp/example.textbundle' }
28
+
29
+ it 'does not exist' do
30
+ expect(text_bundle).not_to exist
31
+ end
32
+
33
+ it 'has no text' do
34
+ expect(text_bundle.text).to eq('')
35
+ end
36
+
37
+ context 'when closed' do
38
+ before do
39
+ text_bundle.close
40
+ end
41
+
42
+ it 'exists' do
43
+ expect(text_bundle).to exist
44
+ end
45
+
46
+ it 'creates the containing folder' do
47
+ expect(File.exist?(text_bundle_path)).to be true
48
+ end
49
+
50
+ it 'creates the text file' do
51
+ expect(File.exist?(text_bundle_path + '/text.markdown')).to be true
52
+ end
53
+
54
+ it 'creates the info file' do
55
+ expect(File.exist?(text_bundle_path + '/info.json')).to be true
56
+ end
57
+ end
58
+
59
+ context 'using a block' do
60
+ let(:text_bundle) do
61
+ described_class.new(text_bundle_path) {}
62
+ end
63
+
64
+ it 'exists' do
65
+ expect(text_bundle).to exist
66
+ end
67
+ end
68
+
69
+ context 'when configuration options are set' do
70
+ before do
71
+ Trundle.configure do |config|
72
+ config.version = 3
73
+ end
74
+ end
75
+
76
+ it 'merges in the config' do
77
+ expect(text_bundle.version).to eq(3)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,41 @@
1
+ RSpec.describe Trundle do
2
+ let(:text_bundle_path) { 'spec/tmp/example.textbundle' }
3
+
4
+ describe '.open' do
5
+ it 'returns an instance' do
6
+ expect(described_class.open(text_bundle_path)).to be_a(Trundle::TextBundle)
7
+ end
8
+
9
+ context 'using a block' do
10
+ let(:text_bundle) { described_class.open(text_bundle_path) {} }
11
+
12
+ it 'passes down to the new instance' do
13
+ expect(text_bundle).to exist
14
+ end
15
+ end
16
+ end
17
+
18
+ describe '.config' do
19
+ it 'returns a config object' do
20
+ expect(Trundle.config).to be_a(Trundle::Config)
21
+ end
22
+
23
+ it 'always returns the same config object' do
24
+ expect(Trundle.config).to equal(Trundle.config)
25
+ end
26
+ end
27
+
28
+ describe '.configure' do
29
+ before do
30
+ Trundle.configure do |config|
31
+ config.version = 1
32
+ config.creator_url = 'http://example.com'
33
+ end
34
+ end
35
+
36
+ it 'writes config values' do
37
+ expect(Trundle.config.version).to eq(1)
38
+ expect(Trundle.config.creator_url).to eq('http://example.com')
39
+ end
40
+ end
41
+ end
@@ -0,0 +1 @@
1
+ {}
File without changes
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 2,
3
+ "io.monkeyisland": {
4
+ "version": 1,
5
+ "localCastaway": "Herman Toothrot"
6
+ },
7
+ "io.scabbisland": {
8
+ "version": 6
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "version" : 2,
3
+ "type": "net.daringfireball.markdown",
4
+ "transient" : true,
5
+ "creatorURL" : "file:\/\/\/Applications\/Example.app\/",
6
+ "creatorIdentifier" : "com.example.editor",
7
+ "sourceURL": "file:\/\/\/Users\/johndoe\/Documents\/myfile.markdown\/"
8
+ }
@@ -0,0 +1,5 @@
1
+ # Textbundle Example
2
+
3
+ This is a simple example of a textbundle package. The following paragraph contains an example of a referenced image using the embedding code `![](assets/textbundle.png)`.
4
+
5
+ ![](assets/textbundle.png)
@@ -0,0 +1,108 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+
20
+ require 'trundle'
21
+
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ # config.filter_run :focus
51
+ # config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ # if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ # config.default_formatter = 'doc'
72
+ # end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ # config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+
91
+ # Keep the spec/tmp directory clean
92
+ config.before(:each) do
93
+ clean_up_tmp_text_bundles
94
+ end
95
+
96
+ config.after(:each) do
97
+ reset_config
98
+ clean_up_tmp_text_bundles
99
+ end
100
+
101
+ def reset_config
102
+ Trundle.remove_instance_variable(:@config) if Trundle.instance_variable_defined?(:@config)
103
+ end
104
+
105
+ def clean_up_tmp_text_bundles
106
+ FileUtils.rm_rf Dir.glob('spec/tmp/*.textbundle'), secure: true
107
+ end
108
+ end
data/spec/tmp/.gitkeep ADDED
File without changes
data/trundle.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trundle/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'trundle'
8
+ spec.version = Trundle::VERSION
9
+ spec.authors = ['Andy Pearson']
10
+ spec.email = ['andy@andy-pearson.com']
11
+ spec.summary = %q{A gem for reading and writing TextBundle files.}
12
+ spec.description = %q{A gem for reading and writing TextBundle files.}
13
+ spec.homepage = 'https://github.com/andypearson/trundle'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'activesupport', '~> 4.2'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.2'
26
+ end