Skip to content

Commit

Permalink
first stabs at build word chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesdeb committed Apr 5, 2020
1 parent dd213c4 commit 91a39a8
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 38 deletions.
12 changes: 12 additions & 0 deletions app/models/text_sample.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# frozen_string_literal: true

class TextSample < ApplicationRecord
validates :description, presence: true
validates :text, presence: true

def build_word_chunks
chunk_sizes = 2..8

chunk_sizes.each do |chunk_size|
build_word_chunks_of_size(chunk_size) unless text.size < chunk_size
end
end

def build_word_chunks_of_size(chunk_size); end
end
2 changes: 2 additions & 0 deletions app/models/word_chunk.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class WordChunk < ApplicationRecord
belongs_to :text_sample

Expand Down
61 changes: 37 additions & 24 deletions spec/examples.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
example_id | status | run_time |
--------------------------------------------- | ------- | --------------- |
./spec/models/text_sample_spec.rb[1:1:1] | passed | 0.02027 seconds |
./spec/models/text_sample_spec.rb[1:1:2] | passed | 0.0024 seconds |
./spec/models/text_sample_spec.rb[1:2:1] | passed | 0.03488 seconds |
./spec/models/text_sample_spec.rb[1:2:2] | pending | 0.00001 seconds |
./spec/models/word_chunk_spec.rb[1:1:1] | passed | 0.00441 seconds |
./spec/models/word_chunk_spec.rb[1:1:2] | passed | 0.00293 seconds |
./spec/models/word_chunk_spec.rb[1:1:3] | passed | 0.00311 seconds |
./spec/models/word_chunk_spec.rb[1:1:4] | passed | 0.0458 seconds |
./spec/requests/text_samples_spec.rb[1:1:1] | passed | 0.01542 seconds |
./spec/requests/text_samples_spec.rb[1:2:1] | passed | 0.01541 seconds |
./spec/requests/text_samples_spec.rb[1:3:1] | passed | 0.01303 seconds |
./spec/requests/text_samples_spec.rb[1:4:1] | passed | 2.21 seconds |
./spec/requests/text_samples_spec.rb[1:5:1:1] | passed | 0.00878 seconds |
./spec/requests/text_samples_spec.rb[1:5:1:2] | failed | 0.00064 seconds |
./spec/requests/text_samples_spec.rb[1:5:1:3] | passed | 0.00876 seconds |
./spec/requests/text_samples_spec.rb[1:5:2:1] | passed | 0.016 seconds |
./spec/requests/text_samples_spec.rb[1:5:2:2] | passed | 0.01428 seconds |
./spec/requests/text_samples_spec.rb[1:6:1:1] | pending | 0.00949 seconds |
./spec/requests/text_samples_spec.rb[1:6:1:2] | passed | 0.01169 seconds |
./spec/requests/text_samples_spec.rb[1:6:2:1] | passed | 0.0159 seconds |
./spec/requests/text_samples_spec.rb[1:7:1] | passed | 0.01494 seconds |
./spec/requests/text_samples_spec.rb[1:7:2] | passed | 0.01152 seconds |
example_id | status | run_time |
----------------------------------------------------- | ------- | --------------- |
./spec/helpers/text_samples_helper_spec.rb[1:1] | pending | 0.00003 seconds |
./spec/models/text_sample_spec.rb[1:1:1] | passed | 0.00371 seconds |
./spec/models/text_sample_spec.rb[1:1:2] | passed | 0.00463 seconds |
./spec/models/text_sample_spec.rb[1:2:1:1] | passed | 0.03304 seconds |
./spec/models/text_sample_spec.rb[1:2:1:2] | passed | 0.0036 seconds |
./spec/models/word_chunk_spec.rb[1:1:1] | passed | 0.00654 seconds |
./spec/models/word_chunk_spec.rb[1:1:2] | passed | 0.0232 seconds |
./spec/models/word_chunk_spec.rb[1:1:3] | passed | 0.00385 seconds |
./spec/models/word_chunk_spec.rb[1:1:4] | passed | 0.0031 seconds |
./spec/requests/text_samples_spec.rb[1:1:1] | passed | 0.02365 seconds |
./spec/requests/text_samples_spec.rb[1:2:1] | passed | 0.01393 seconds |
./spec/requests/text_samples_spec.rb[1:3:1] | passed | 2.24 seconds |
./spec/requests/text_samples_spec.rb[1:4:1] | passed | 0.03572 seconds |
./spec/requests/text_samples_spec.rb[1:5:1:1] | passed | 0.00784 seconds |
./spec/requests/text_samples_spec.rb[1:5:1:2] | failed | 0.01819 seconds |
./spec/requests/text_samples_spec.rb[1:5:1:3] | passed | 0.00772 seconds |
./spec/requests/text_samples_spec.rb[1:5:2:1] | passed | 0.01638 seconds |
./spec/requests/text_samples_spec.rb[1:5:2:2] | passed | 0.01606 seconds |
./spec/requests/text_samples_spec.rb[1:6:1:1] | pending | 0.01364 seconds |
./spec/requests/text_samples_spec.rb[1:6:1:2] | passed | 0.01511 seconds |
./spec/requests/text_samples_spec.rb[1:6:2:1] | passed | 0.04019 seconds |
./spec/requests/text_samples_spec.rb[1:7:1] | passed | 0.01801 seconds |
./spec/requests/text_samples_spec.rb[1:7:2] | passed | 0.01515 seconds |
./spec/routing/text_samples_routing_spec.rb[1:1:1] | passed | 0.00081 seconds |
./spec/routing/text_samples_routing_spec.rb[1:1:2] | passed | 0.00114 seconds |
./spec/routing/text_samples_routing_spec.rb[1:1:3] | passed | 0.00078 seconds |
./spec/routing/text_samples_routing_spec.rb[1:1:4] | passed | 0.00087 seconds |
./spec/routing/text_samples_routing_spec.rb[1:1:5] | passed | 0.00143 seconds |
./spec/routing/text_samples_routing_spec.rb[1:1:6] | passed | 0.00099 seconds |
./spec/routing/text_samples_routing_spec.rb[1:1:7] | passed | 0.0039 seconds |
./spec/routing/text_samples_routing_spec.rb[1:1:8] | passed | 0.00101 seconds |
./spec/views/text_samples/edit.html.erb_spec.rb[1:1] | passed | 0.00769 seconds |
./spec/views/text_samples/index.html.erb_spec.rb[1:1] | passed | 0.01657 seconds |
./spec/views/text_samples/new.html.erb_spec.rb[1:1] | passed | 0.02457 seconds |
./spec/views/text_samples/show.html.erb_spec.rb[1:1] | passed | 0.01983 seconds |
13 changes: 10 additions & 3 deletions spec/factories/text_sample.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# frozen_string_literal: true

# This will guess the TextSample class
FactoryBot.define do
factory :text_sample_simple, class: TextSample do
description { 'Simple' }
text { 'The man in the mirror' }
factory :text_sample_two_chars, class: TextSample do
description { 'Two characters' }
text { 'At' }
end

factory :text_sample_three_chars, class: TextSample do
description { 'Three characters' }
text { 'The' }
end
end
35 changes: 31 additions & 4 deletions spec/models/text_sample_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe TextSample, type: :model do
RSpec.describe TextSample, type: :model do # rubocop:disable Metrics/BlockLength
describe 'validations' do
it { should validate_presence_of(:description) }
it { should validate_presence_of(:text) }
end

# describe '::class_method' do
describe '#build_word_chunks' do
let(:text_sample){ create(:text_sample_simple) }
it 'counts word chunks'
it 'assigns the word chunks to this text sample'
describe 'builds different sized chunks' do
it 'handles 2 character chunks' do
text_sample = create(:text_sample_two_chars)
allow(text_sample).to receive(:build_word_chunks_of_size)
text_sample.build_word_chunks

expect(text_sample).to(
have_received(:build_word_chunks_of_size).with(2).once
)
expect(text_sample).not_to(
have_received(:build_word_chunks_of_size).with(3)
)
end

it 'handles 3 character chunks' do
text_sample = create(:text_sample_three_chars)
allow(text_sample).to receive(:build_word_chunks_of_size)
text_sample.build_word_chunks

expect(text_sample).to(
have_received(:build_word_chunks_of_size).with(2).once
)
expect(text_sample).to(
have_received(:build_word_chunks_of_size).with(3).once
)
end
end
end
end
13 changes: 9 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
Expand Down Expand Up @@ -44,8 +46,8 @@
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# This allows you to limit a spec run to individual examples or groups
# you care about by tagging them with `:focus` metadata. When nothing
# is tagged with `:focus`, all examples get run. RSpec also provides
Expand All @@ -56,7 +58,7 @@
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
config.example_status_persistence_file_path = 'spec/examples.txt'

# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
Expand All @@ -72,7 +74,7 @@
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = "doc"
config.default_formatter = 'doc'
end

# Print the 10 slowest examples and example groups at the
Expand All @@ -91,4 +93,7 @@
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed

# CdeB custom changes
config.default_formatter = 'doc'
end
4 changes: 1 addition & 3 deletions spec/support/factory_bot.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
puts "ljksfdlkfjlkjsdlkfdklfj"

RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
end

0 comments on commit 91a39a8

Please sign in to comment.