diff --git a/.gitignore b/.gitignore index 76a0bf1..e97cbc1 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,52 @@ -_site -.sass-cache +# Ruby specific +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Bundler specific Gemfile.lock +.bundle/ +vendor/bundle + +# Jekyll specific +_site/ +.sass-cache/ +.jekyll-metadata +.jekyll-cache/ + +# Dependency directories +node_modules/ +jspm_packages/ + +# Environment variables +.env +.env.local +.env.development.local +.env.test.local +.env.production.local + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Editor/IDE files +.idea/ +.vscode/ +*.swp +*.swo +*~ + +# System files +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..5255835 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--color +--format documentation +--require spec_helper \ No newline at end of file diff --git a/Gemfile b/Gemfile index ded3333..18fbb16 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ -source "https://rubygems.org" +source 'https://rubygems.org' -gem "github-pages", ">= 25" -gem 'webrick' -gem 'csv' \ No newline at end of file +group :development, :test do + gem 'rspec', '~> 3.12' +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..81a3a69 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,11 @@ +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + + config.shared_context_metadata_behavior = :apply_to_host_groups +end \ No newline at end of file diff --git a/src/author_validator.rb b/src/author_validator.rb new file mode 100644 index 0000000..6bf40f0 --- /dev/null +++ b/src/author_validator.rb @@ -0,0 +1,12 @@ +class AuthorValidator + MAX_NAME_LENGTH = 100 + + def self.validate(author) + return false if author.nil? || author.strip.empty? + return false if author.length > MAX_NAME_LENGTH + + # Optional: Additional validation rules can be added here + # For example, validate allowed characters, no special rules for now + true + end +end \ No newline at end of file diff --git a/test/author_validator_spec.rb b/test/author_validator_spec.rb new file mode 100644 index 0000000..b5fd44a --- /dev/null +++ b/test/author_validator_spec.rb @@ -0,0 +1,35 @@ +require_relative '../src/author_validator' + +RSpec.describe AuthorValidator do + describe '.validate' do + context 'when author is valid' do + it 'returns true for a standard name' do + expect(AuthorValidator.validate('John Doe')).to be true + end + + it 'returns true for a name at max length' do + long_name = 'a' * 100 + expect(AuthorValidator.validate(long_name)).to be true + end + end + + context 'when author is invalid' do + it 'returns false for nil author' do + expect(AuthorValidator.validate(nil)).to be false + end + + it 'returns false for empty string' do + expect(AuthorValidator.validate(''))).to be false + end + + it 'returns false for whitespace-only string' do + expect(AuthorValidator.validate(' ')).to be false + end + + it 'returns false for name exceeding max length' do + long_name = 'a' * 101 + expect(AuthorValidator.validate(long_name)).to be false + end + end + end +end \ No newline at end of file