smashing_docs 1.1.0 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26647e5613a7de2ae48b1b45290021d6421c2fbc
4
- data.tar.gz: d3895c49e8d1f5cc6703cc9fc3e03d599794068f
3
+ metadata.gz: 15b0e44e0f4ab5badf91ecddfefb2851bbac26f5
4
+ data.tar.gz: e7541a662104c2fce5e3e666fc9dc42189f2aa44
5
5
  SHA512:
6
- metadata.gz: dab20613149d2467798fe72dc8fbaa72980c82514a499eed11f2bf6c079b6a79990e82b479af5d415188910ffac121937f4da5586f9a8bba7c787ef5964952a9
7
- data.tar.gz: d6946b59dd25a634d646d6951d7e222affb951b2ce9fce69b90fde20aa1d09317f37b03b26419b6b27c88cace31955e13b78d62a5f7e24551721191a37eb5f0f
6
+ metadata.gz: 0e2ff24eaa86feeb14762486a067f92f20226b2be8ed5d3d0c983e681cc573d406e46d3af8f25e7c49cda7e12d69ee1c40bc25924c53b7598492bf672abf1767
7
+ data.tar.gz: 79625ae7e3b62aa49b32b4954bd1c80b5f8eecf8a8857040bd850d22ccaf37191b971e9e29450ffbbf55f2c4075d854827b7d7cf74cb73a6e39c4e3670f625a6
data/README.md CHANGED
@@ -10,7 +10,7 @@ In your gemfile add the following to your test group:
10
10
 
11
11
  Installation differs for RSpec/Minitest, so scroll to the appropriate section for guidance.
12
12
 
13
- ## Automatic Installation (RSpec only!)
13
+ ## Automatic Installation (RSpec or Minitest!)
14
14
 
15
15
  After you bundle, run:
16
16
 
@@ -19,10 +19,13 @@ After you bundle, run:
19
19
  SmashingDocs will be configured to run on all your controller tests with the default
20
20
  template.
21
21
 
22
+ If you're using RSpec and you haven't required `rails_helper` in your tests, do that now.
23
+
24
+ `require 'rails_helper'`
25
+
22
26
  #### To generate your docs
23
27
 
24
- Run `rails g smashing_documentation:build_docs`, and your docs will be waiting for you
25
- in the `smashing_docs` folder.
28
+ Run `rails g smashing_documentation:build_docs`, and your docs will be waiting for you in the `smashing_docs` folder.
26
29
 
27
30
  ## Manual RSpec Installation
28
31
 
@@ -32,6 +35,7 @@ Add this to your `rails_helper.rb` It should go outside of other blocks
32
35
  SmashingDocs.config do |c|
33
36
  c.template_file = 'smashing_docs/template.md'
34
37
  c.output_file = 'smashing_docs/api_docs.md'
38
+ c.auto_push = false
35
39
  c.run_all = true
36
40
  end
37
41
  ```
@@ -57,6 +61,7 @@ Set the `c.run_all` line to `false` in `rails_helper.rb`
57
61
  SmashingDocs.config do |c|
58
62
  c.template_file = 'smashing_docs/template.md'
59
63
  c.output_file = 'smashing_docs/api_docs.md'
64
+ c.auto_push = false
60
65
  c.run_all = false
61
66
  end
62
67
  ```
@@ -79,6 +84,7 @@ class ActiveSupport::TestCase
79
84
  SmashingDocs.config do |c|
80
85
  c.template_file = 'smashing_docs/template.md'
81
86
  c.output_file = 'smashing_docs/api_docs.md'
87
+ c.auto_push = false
82
88
  c.run_all = true
83
89
  end
84
90
  # More code
@@ -99,6 +105,7 @@ Set the `c.run_all` line to `false` in `test_helper.rb`
99
105
  SmashingDocs.config do |c|
100
106
  c.template_file = 'smashing_docs/template.md'
101
107
  c.output_file = 'smashing_docs/api_docs.md'
108
+ c.auto_push = false
102
109
  c.run_all = false
103
110
  end
104
111
  ```
@@ -6,18 +6,23 @@ RSpec.describe SmashingDocumentation::Generators::InstallGenerator, type: :gener
6
6
  let(:spec_helper) { "spec/spec_helper.rb" }
7
7
  let(:docs_template) { "smashing_docs/template.md" }
8
8
  context "when rspec is installed" do
9
- describe "#update_spec_helper" do
9
+ describe "#configure_smashing_docs" do
10
+ let(:rails_helper) { "spec/rails_helper.rb" }
10
11
  it "appends the SmashingDocs config to rails_helper.rb" do
11
12
  run_generator
12
13
  expect(File).to exist(rails_helper)
13
14
  expect(File.read(rails_helper)).to include("SmashingDocs.config do")
15
+ `rm -r smashing_docs`
14
16
  end
15
-
17
+ end
18
+ describe "#add_rspec_hooks" do
19
+ let(:spec_helper) { "spec/spec_helper.rb" }
16
20
  it "appends test suite hooks inside RSpec.configure block in spec_helper.rb" do
17
21
  run_generator
18
22
  expect(File).to exist(spec_helper)
19
23
  expect(File.read(spec_helper)).to include("config.after(:each,")
20
24
  expect(File.read(spec_helper)).to include("config.after(:suite)")
25
+ `rm -r smashing_docs`
21
26
  end
22
27
  end
23
28
 
@@ -27,17 +32,49 @@ RSpec.describe SmashingDocumentation::Generators::InstallGenerator, type: :gener
27
32
  expect(File).to exist(docs_template)
28
33
  expect(File.read(docs_template)).to include("request.method")
29
34
  expect(File.read(docs_template)).to include("response.body")
35
+ `rm -r smashing_docs`
36
+ end
37
+ end
38
+ end
39
+
40
+ context "when minitest is installed" do
41
+ describe "#configure_smashing_docs" do
42
+ let(:test_helper) { "test/test_helper.rb" }
43
+ it "appends the SmashingDocs config to test_helper.rb" do
44
+ `mv spec s`
45
+ run_generator
46
+ expect(File).to exist(test_helper)
47
+ expect(File.read(test_helper)).to include("SmashingDocs.config do")
48
+ `rm #{test_helper}`
49
+ `mv s spec`
50
+ `rm -r smashing_docs`
51
+ end
52
+ end
53
+
54
+ describe "#add_minitest_hooks" do
55
+ let(:test_helper) { "test/test_helper.rb" }
56
+ it "appends test suite hooks inside to the test_helper.rb" do
57
+ `mv spec s`
58
+ run_generator
59
+ expect(File).to exist(test_helper)
60
+ expect(File.read(test_helper)).to include("teardown")
61
+ expect(File.read(test_helper)).to include("after_tests")
62
+ expect(File.read(test_helper)).to include("SmashingDocs")
63
+ `mv s spec`
64
+ `rm #{test_helper}`
65
+ `rm -r smashing_docs`
30
66
  end
31
67
  end
32
68
  end
33
- context "when rspec is not installed" do
69
+ context "when no test suite is installed" do
34
70
  it "does not install smashing_docs" do
35
- `rm -f "#{rails_helper}"`
71
+ `rm "#{rails_helper}"`
36
72
  File.rename('spec', 's') if Dir.exists?('spec')
73
+ File.rename('test', 't') if Dir.exists?('test')
37
74
  run_generator
38
75
  File.rename('s', 'spec') if Dir.exists?('s')
76
+ File.rename('t', 'test') if Dir.exists?('t')
39
77
  expect(File).to_not exist(rails_helper)
40
-
41
78
  # STDOUT is not tested here because it is suppressed in generator tests
42
79
  end
43
80
  end
@@ -6,49 +6,93 @@ module SmashingDocumentation
6
6
 
7
7
  def install
8
8
  if Dir.exists?('spec')
9
- update_rails_helper
10
- update_spec_helper
11
- generate_docs_template
9
+ @config_file = "spec/rails_helper.rb"
10
+ elsif Dir.exists?('test')
11
+ @config_file = "test/test_helper.rb"
12
12
  else
13
- puts "It does not appear that you have RSpec installed in your app"
14
- puts "Please set up RSpec before running this installer"
13
+ puts "It does not appear that you have a test suite installed in your app"
14
+ puts "Please...please use tests"
15
+ return
15
16
  end
17
+ configure_smashing_docs
18
+ using_minitest? ? add_minitest_hooks : add_rspec_hooks
19
+ generate_docs_template
16
20
  end
17
21
 
18
22
  private
23
+ def configure_smashing_docs
24
+ create_config_file
25
+ add_configuration
26
+ end
19
27
 
20
- def update_rails_helper
21
- destination = "spec/rails_helper.rb"
22
- create_file(destination) unless File.exist?(destination)
23
- append_file(destination,
24
- "SmashingDocs.config do |c|\n"\
25
- " c.template_file = 'smashing_docs/template.md'\n"\
26
- " c.output_file = 'smashing_docs/api_docs.md'\n"\
27
- " c.auto_push = false\n"\
28
- " c.run_all = true\n"\
29
- "end"
30
- ) unless File.readlines(destination).grep(/SmashingDocs.config/).any?
31
- end
32
-
33
- def update_spec_helper
34
- destination = "spec/spec_helper.rb"
35
- if File.exist?(destination)
28
+ def add_rspec_hooks
29
+ helper = "spec/spec_helper.rb"
30
+ if File.exist?(helper)
36
31
  insert_into_file(
37
- destination,
32
+ helper,
38
33
  "\n config.after(:each, type: :controller) do\n"\
39
34
  " SmashingDocs.run!(request, response, true)\n"\
40
35
  " end\n"\
41
36
  " # config.after(:suite) { SmashingDocs.finish! }",
42
37
  after: "RSpec.configure do |config|"
43
- ) unless File.readlines(destination).grep(/SmashingDocs.finish/).any?
38
+ ) unless test_hooks_already_setup?(helper)
44
39
  end
45
40
  end
46
41
 
42
+ def add_minitest_hooks
43
+ helper = "test/test_helper.rb"
44
+ append_file(
45
+ helper,
46
+ "\nclass ActionController::TestCase < ActiveSupport::TestCase\n"\
47
+ " def teardown\n"\
48
+ " SmashingDocs.run!(request, response, true)\n"\
49
+ " end\n"\
50
+ "end\n"\
51
+ "MiniTest::Unit.after_tests { SmashingDocs.finish! }\n"
52
+ ) unless test_hooks_already_setup?(helper)
53
+ end
54
+
47
55
  def generate_docs_template
48
56
  source = "real_template.md"
49
57
  destination = "smashing_docs/template.md"
50
58
  copy_file(source, destination) unless File.exist?(destination)
51
59
  end
60
+
61
+ def create_config_file
62
+ unless File.exist?(@config_file)
63
+ create_file(@config_file)
64
+ append_file(@config_file, "class ActiveSupport::TestCase\n end\n") if using_minitest?
65
+ end
66
+ end
67
+
68
+ def add_configuration
69
+ setup_configuration unless config_already_setup?
70
+ end
71
+
72
+ def setup_configuration
73
+ config = "SmashingDocs.config do |c|\n"\
74
+ " c.template_file = 'smashing_docs/template.md'\n"\
75
+ " c.output_file = 'smashing_docs/api_docs.md'\n"\
76
+ " c.auto_push = false\n"\
77
+ "end\n"
78
+ if using_minitest?
79
+ insert_into_file(@config_file, config, after: "class ActiveSupport::TestCase\n")
80
+ else
81
+ append_file(@config_file, config)
82
+ end
83
+ end
84
+
85
+ def config_already_setup?
86
+ File.readlines(@config_file).grep(/SmashingDocs.config/).any?
87
+ end
88
+
89
+ def test_hooks_already_setup?(helper)
90
+ File.readlines(helper).grep(/SmashingDocs\.run!/).any?
91
+ end
92
+
93
+ def using_minitest?
94
+ @config_file.include?("test")
95
+ end
52
96
  end
53
97
  end
54
98
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.require_paths = ['lib']
11
11
  s.summary = "Uses your test cases to write example documentation for your API."
12
12
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
- s.version = '1.1.0'
13
+ s.version = '1.2.0'
14
14
 
15
15
  s.add_development_dependency "bundler", "~> 1.11"
16
16
  s.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smashing_docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Rockwell
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-02-29 00:00:00.000000000 Z
13
+ date: 2016-03-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -80,7 +80,6 @@ files:
80
80
  - Gemfile.lock
81
81
  - README.md
82
82
  - Rakefile
83
- - api_docs.md
84
83
  - documentation.md
85
84
  - gem_rspec/base_spec.rb
86
85
  - gem_rspec/conf_spec.rb
data/api_docs.md DELETED
File without changes