diff --git a/CHANGELOG.md b/CHANGELOG.md index 3500017f..aad7aca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Unreleased ([changes](https://github.com/colszowka/simplecov/compare/v0.7.0...ma ------------------- * [FEATURE] Adds support for Rails 4 command guessing. + * Rename adapters to "profiles" given that they are bundles of settings v0.7.1, 2012-10-12 ([changes](https://github.com/colszowka/simplecov/compare/v0.7.0...v0.7.1)) ------------------- diff --git a/README.md b/README.md index 5e03043b..2476f696 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ end coverage -If you're making a Rails application, SimpleCov comes with a built-in adapter (see below for more information on what adapters are) +If you're making a Rails application, SimpleCov comes with a built-in configurations (see below for information on profiles) which will get you started with groups for your Controllers, Views, Models and Helpers. To use it, the first two lines of your test_helper should be like this: @@ -388,17 +388,17 @@ COVERAGE=true rake test ``` -## Adapters +## Profiles By default, Simplecov's only config assumption is that you only want coverage reports for files inside your project -root. To save you from repetitive configuration, you can use predefined blocks of configuration, called 'adapters', +root. To save you from repetitive configuration, you can use predefined blocks of configuration, called 'profiles', or define your own. -You can then pass the name of the adapter to be used as the first argument to SimpleCov.start. For example, simplecov -comes bundled with a 'rails' adapter. It looks somewhat like this: +You can then pass the name of the profile to be used as the first argument to SimpleCov.start. For example, simplecov +comes bundled with a 'rails' profile. It looks somewhat like this: ```ruby -SimpleCov.adapters.define 'rails' do +SimpleCov.profiles.define 'rails' do add_filter '/test/' add_filter '/config/' @@ -410,7 +410,7 @@ SimpleCov.adapters.define 'rails' do end ``` -As you can see, it's just a glorified SimpleCov.configure block. In your test_helper.rb, launch simplecov with: +As you can see, it's just a SimpleCov.configure block. In your test_helper.rb, launch simplecov with: ```ruby SimpleCov.start 'rails' @@ -424,26 +424,26 @@ SimpleCov.start 'rails' do end ``` -### Custom adapters +### Custom profiles -You can load additional adapters with the SimpleCov.load_adapter('xyz') method. This allows you to build upon an existing -adapter and customize it so you can reuse it in unit tests and cucumber features, for example. +You can load additional profiles with the SimpleCov.load_profile('xyz') method. This allows you to build upon an existing +profile and customize it so you can reuse it in unit tests and cucumber features, for example. ```ruby -# lib/simplecov_custom_adapter.rb +# lib/simplecov_custom_profile.rb require 'simplecov' -SimpleCov.adapters.define 'myadapter' do - load_adapter 'rails' +SimpleCov.profiles.define 'myprofile' do + load_profile 'rails' add_filter 'vendor' # Don't include vendored stuff end # features/support/env.rb -require 'simplecov_custom_adapter' -SimpleCov.start 'myadapter' +require 'simplecov_custom_profile' +SimpleCov.start 'myprofile' # test/test_helper.rb -require 'simplecov_custom_adapter' -SimpleCov.start 'myadapter' +require 'simplecov_custom_profile' +SimpleCov.start 'myprofile' ``` diff --git a/features/config_adapters.feature b/features/config_adapters.feature deleted file mode 100644 index 3a6ed38c..00000000 --- a/features/config_adapters.feature +++ /dev/null @@ -1,44 +0,0 @@ -@test_unit @config @adapters -Feature: - - In order to re-use SimpleCov settings across projects, - adapters can be defined that hold configuration settings - that can be loaded at once. - - Background: - Given SimpleCov for Test/Unit is configured with: - """ - require 'simplecov' - """ - - Scenario: Defining and using a custom adapter - Given a file named ".simplecov" with: - """ - SimpleCov.adapters.define 'custom_command' do - command_name "Adapter Command" - end - - SimpleCov.start do - load_adapter 'test_frameworks' - load_adapter 'custom_command' - end - """ - - When I open the coverage report generated with `bundle exec rake test` - Then I should see "4 files in total." - And I should see "using Adapter Command" within "#footer" - - Scenario: Using existing adapter in custom adapter and supplying adapter to start command - Given a file named ".simplecov" with: - """ - SimpleCov.adapters.define 'my_adapter' do - load_adapter 'test_frameworks' - command_name "My Adapter" - end - - SimpleCov.start 'my_adapter' - """ - - When I open the coverage report generated with `bundle exec rake test` - Then I should see "4 files in total." - And I should see "using My Adapter" within "#footer" diff --git a/features/config_profiles.feature b/features/config_profiles.feature new file mode 100644 index 00000000..27c0c723 --- /dev/null +++ b/features/config_profiles.feature @@ -0,0 +1,44 @@ +@test_unit @config @profiles +Feature: + + In order to re-use SimpleCov settings across projects, + profiles can be defined that hold configuration settings + that can be loaded at once. + + Background: + Given SimpleCov for Test/Unit is configured with: + """ + require 'simplecov' + """ + + Scenario: Defining and using a custom profile + Given a file named ".simplecov" with: + """ + SimpleCov.profiles.define 'custom_command' do + command_name "Profile Command" + end + + SimpleCov.start do + load_profile 'test_frameworks' + load_profile 'custom_command' + end + """ + + When I open the coverage report generated with `bundle exec rake test` + Then I should see "4 files in total." + And I should see "using Profile Command" within "#footer" + + Scenario: Using existing profile in custom profile and supplying profile to start command + Given a file named ".simplecov" with: + """ + SimpleCov.profiles.define 'my_profile' do + load_profile 'test_frameworks' + command_name "My Profile" + end + + SimpleCov.start 'my_profile' + """ + + When I open the coverage report generated with `bundle exec rake test` + Then I should see "4 files in total." + And I should see "using My Profile" within "#footer" diff --git a/lib/simplecov.rb b/lib/simplecov.rb index 2f529d29..01da4201 100644 --- a/lib/simplecov.rb +++ b/lib/simplecov.rb @@ -7,10 +7,10 @@ class << self # # Sets up SimpleCov to run against your project. - # You can optionally specify an adapter to use as well as configuration with a block: + # You can optionally specify a profile to use as well as configuration with a block: # SimpleCov.start # OR - # SimpleCov.start 'rails' # using rails adapter + # SimpleCov.start 'rails' # using rails profile # OR # SimpleCov.start do # add_filter 'test' @@ -22,9 +22,9 @@ class << self # # Please check out the RDoc for SimpleCov::Configuration to find about available config options # - def start(adapter=nil, &block) + def start(profile=nil, &block) if SimpleCov.usable? - load_adapter(adapter) if adapter + load_profile(profile) if profile configure(&block) if block_given? @result = nil self.running = true @@ -89,10 +89,15 @@ def grouped(files) end # - # Applies the adapter of given name on SimpleCov configuration + # Applies the profile of given name on SimpleCov configuration # + def load_profile(name) + profiles.load(name) + end + def load_adapter(name) - adapters.load(name) + warn "method load_adapter is deprecated. use load_profile instead" + load_profile(name) end # @@ -118,7 +123,7 @@ def usable? SimpleCov.send :extend, SimpleCov::Configuration require 'simplecov/exit_codes' require 'simplecov/json' -require 'simplecov/adapters' +require 'simplecov/profiles' require 'simplecov/source_file' require 'simplecov/file_list' require 'simplecov/result' diff --git a/lib/simplecov/configuration.rb b/lib/simplecov/configuration.rb index 960aab78..d3bb1b56 100644 --- a/lib/simplecov/configuration.rb +++ b/lib/simplecov/configuration.rb @@ -94,10 +94,15 @@ def groups end # - # Returns the hash of available adapters + # Returns the hash of available profiles # + def profiles + @profiles ||= SimpleCov::Profiles.new + end + def adapters - @adapters ||= SimpleCov::Adapters.new + warn "method adapters is deprecated. use profiles instead" + profiles end # diff --git a/lib/simplecov/defaults.rb b/lib/simplecov/defaults.rb index e34ddbf9..5b85de20 100644 --- a/lib/simplecov/defaults.rb +++ b/lib/simplecov/defaults.rb @@ -1,22 +1,22 @@ # Load default formatter gem require 'simplecov-html' -SimpleCov.adapters.define 'root_filter' do +SimpleCov.profiles.define 'root_filter' do # Exclude all files outside of simplecov root add_filter do |src| !(src.filename =~ /^#{SimpleCov.root}/) end end -SimpleCov.adapters.define 'test_frameworks' do +SimpleCov.profiles.define 'test_frameworks' do add_filter '/test/' add_filter '/features/' add_filter '/spec/' add_filter '/autotest/' end -SimpleCov.adapters.define 'rails' do - load_adapter 'test_frameworks' +SimpleCov.profiles.define 'rails' do + load_profile 'test_frameworks' add_filter '/config/' add_filter '/db/' @@ -34,7 +34,7 @@ SimpleCov.configure do formatter SimpleCov::Formatter::HTMLFormatter # Exclude files outside of SimpleCov.root - load_adapter 'root_filter' + load_profile 'root_filter' end # Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info diff --git a/lib/simplecov/adapters.rb b/lib/simplecov/profiles.rb similarity index 50% rename from lib/simplecov/adapters.rb rename to lib/simplecov/profiles.rb index bb2611bd..bf254788 100644 --- a/lib/simplecov/adapters.rb +++ b/lib/simplecov/profiles.rb @@ -1,29 +1,29 @@ # -# Adapters are glorified SimpleCov configuration procs that can be easily +# Profiles are SimpleCov configuration procs that can be easily # loaded using SimpleCov.start :rails and defined using -# SimpleCov.adapters.define :foo do +# SimpleCov.profiles.define :foo do # # SimpleCov configuration here, same as in SimpleCov.configure # end # -class SimpleCov::Adapters < Hash +class SimpleCov::Profiles < Hash # - # Define a SimpleCov adapter: - # SimpleCov.adapters.define 'rails' do + # Define a SimpleCov profile: + # SimpleCov.profiles.define 'rails' do # # Same as SimpleCov.configure do .. here # end # def define(name, &blk) name = name.to_sym - raise "SimpleCov Adapter '#{name}' is already defined" unless self[name].nil? + raise "SimpleCov Profile '#{name}' is already defined" unless self[name].nil? self[name] = blk end # - # Applies the adapter of given name on SimpleCov.configure + # Applies the profile of given name on SimpleCov.configure # def load(name) name = name.to_sym - raise "Could not find SimpleCov Adapter called '#{name}'" unless has_key?(name) + raise "Could not find SimpleCov Profile called '#{name}'" unless has_key?(name) SimpleCov.configure(&self[name]) end end diff --git a/test/test_1_8_fallbacks.rb b/test/test_1_8_fallbacks.rb index 6b258ef9..4b2a213e 100644 --- a/test/test_1_8_fallbacks.rb +++ b/test/test_1_8_fallbacks.rb @@ -19,13 +19,13 @@ class Test18FallBacks < Test::Unit::TestCase assert_equal false, SimpleCov.configure { raise "Shouldn't reach this!?" } end - should "allow to define an adapter" do + should "allow to define a profile" do begin - SimpleCov.adapters.define 'testadapter' do + SimpleCov.profiles.define 'testprofile' do add_filter '/config/' end rescue => err - assert false, "Adapter definition should have been fine, but raised #{err}" + assert false, "Profile definition should have been fine, but raised #{err}" end end end if RUBY_VERSION.start_with? '1.8'