<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Samason4</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Samason4"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Samason4"/>
	<updated>2026-05-11T10:59:49Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156910</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156910"/>
		<updated>2024-04-24T23:26:21Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Model Overview &amp;amp; Test Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
We are unable to find anything that invokes this view_translation_subsitutor throughout the rest of the expertiza code base, so we have created unit tests to verify its functionality independently to ensure that it integrates smoothly with other modules without any issues.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
While implementing the view translation substitution functionality using the ViewTranslationSubstitutor class, the following design goals should be ensured:&lt;br /&gt;
&lt;br /&gt;
* '''Goal #1:''' Determine the purpose and invocation timing of view_translation_substitutor.rb to understand its role in the application's internationalization process and ensure proper integration with the existing codebase.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #2:''' Debug and fix the substitute() method to ensure it correctly processes the locale hash, generates accurate translation statistics, and writes them to the YAML file, handling any edge cases or error scenarios that may arise.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #3:''' Write comprehensive test cases for the key methods of the ViewTranslationSubstitutor class, including substitute, process_directory, process_view, and process_translation, to validate their correctness, robustness, and adherence to the expected behavior.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #4:''' Extend the test suite to cover edge cases and exceptional scenarios, such as empty or invalid locale hashes, missing view files or directories, translation keys with special characters, and performance testing with large or complex view files, ensuring the class handles these situations gracefully and maintains its reliability.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
''Parameters:'' locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# The class replaces hardcoded strings in view templates with translated versions according to the provided locale hash.&lt;br /&gt;
# The class keeps the content of the Expertiza application up-to-date with the latest translations, maintaining consistency and relevance in multiple languages.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#substitute' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  it 'iterates over the locale hash and processes directories' do&lt;br /&gt;
    # Create a sample locale hash.&lt;br /&gt;
    locale = {&lt;br /&gt;
      'dir1' =&amp;gt; { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } },&lt;br /&gt;
      'dir2' =&amp;gt; { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    # Expect process_directory to be called for each directory in the locale hash.&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir1', { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } }).and_return('stats1')&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir2', { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }).and_return('stats2')&lt;br /&gt;
&lt;br /&gt;
    # Expect File.open to be called with a regex matching translation_stats*.yml and write the processed stats to YAML.&lt;br /&gt;
    expect(File).to receive(:open).with(/^translation_stats.*\.yml$/, 'w').and_yield(file = double)&lt;br /&gt;
    expect(file).to receive(:write).with({ 'dir1' =&amp;gt; 'stats1', 'dir2' =&amp;gt; 'stats2' }.to_yaml)&lt;br /&gt;
&lt;br /&gt;
    # Call the substitute method with the sample locale hash.&lt;br /&gt;
    substitutor.substitute(locale)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model can ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When interacting with a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_directory' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is not empty' do&lt;br /&gt;
    let(:dir_name) { 'dir1' }&lt;br /&gt;
    let(:view_hash) { { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } } }&lt;br /&gt;
&lt;br /&gt;
    it 'processes each view in the view_hash' do&lt;br /&gt;
      # Stub process_view method to return 'stats1' and ensure it is called with correct arguments.&lt;br /&gt;
      allow(substitutor).to receive(:process_view).and_return('stats1')&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({ 'view1' =&amp;gt; 'stats1' })&lt;br /&gt;
      expect(substitutor).to have_received(:process_view).with(dir_name, 'view1', { 'key1' =&amp;gt; 'val1' })&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is empty' do&lt;br /&gt;
    # Local variables&lt;br /&gt;
    let(:dir_name) { 'dir2' }&lt;br /&gt;
    let(:view_hash) { {} }&lt;br /&gt;
&lt;br /&gt;
    it 'returns an empty hash' do&lt;br /&gt;
      # Call the private method process_directory with an empty view_hash and ensure it returns an empty hash.&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({})&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When interacting with a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file, then the display placeholders indicating missing translations.&lt;br /&gt;
# When the filenames begin with an underscore, the files should be handled as if they don't begin with an underscore.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_view' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
  let(:directory_name) { 'test_folder' }&lt;br /&gt;
  let(:view_name) { 'example_view' }&lt;br /&gt;
  let(:translations) { { 'key1' =&amp;gt; 'value1', 'key2' =&amp;gt; 'value2' } }&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return true and File.open to yield &amp;quot;Existing content&amp;quot;.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file does not exist' do&lt;br /&gt;
    it 'returns &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;' do&lt;br /&gt;
      # Call the process_view method and expect it to return &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq('&amp;lt;file not found&amp;gt;')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the alternate view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return false for main view file and true for alternate view file.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(false)&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the alternate file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the alternate view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model will incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When interacting with a marketer, the model will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file, then the model will log the error.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content, the model will properly render the HTML file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_translation' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:contents) { 'This is a test string with some &amp;quot;text&amp;quot; to be replaced.' }&lt;br /&gt;
  let(:key) { 'other word' }&lt;br /&gt;
  let(:val) { 'text' }&lt;br /&gt;
  let(:key2) { 'skipped key' }&lt;br /&gt;
  let(:val2) { 'string' }&lt;br /&gt;
  let(:key3) { 'non-existent key' }&lt;br /&gt;
  let(:val3) { 'non-existent val' }&lt;br /&gt;
&lt;br /&gt;
  it 'replaces the correct text with translation keys' do&lt;br /&gt;
    # Call process_translation with a valid key and value and expect correct replacements and modified content.&lt;br /&gt;
    replacements, new_contents = substitutor.send(:process_translation, contents, key, val)&lt;br /&gt;
&lt;br /&gt;
    expect(replacements).to include(&amp;quot;replacements&amp;quot; =&amp;gt; [&amp;quot;\&amp;quot;#{val}\&amp;quot;&amp;quot;])&lt;br /&gt;
    expect(new_contents).to include(&amp;quot;#{key}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds to skip when one value is not found but another value is' do&lt;br /&gt;
    # Call process_translation with a key and value that partially match the contents and expect skips and unmodified content.&lt;br /&gt;
    skips, new_contents = substitutor.send(:process_translation, contents, key2, val2)&lt;br /&gt;
&lt;br /&gt;
    expect(skips).to include(&amp;quot;skips&amp;quot; =&amp;gt; [&amp;quot;test string with&amp;quot;])&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key2}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds &amp;lt;unmatched&amp;gt; to translation_stats when there is no match' do&lt;br /&gt;
    # Call process_translation with a key and value that do not match any part of the contents and expect &amp;lt;unmatched&amp;gt; and unmodified content.&lt;br /&gt;
    translation_stats, new_contents = substitutor.send(:process_translation, contents, key3, val3)&lt;br /&gt;
&lt;br /&gt;
    expect(translation_stats).to include(&amp;quot;&amp;lt;unmatched&amp;gt;&amp;quot;)&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key3}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video (Youtube)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[https://vimeo.com/938411539?share=copy Demo Video (Vimeo)]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We were unable to test view_translation_substitutor.rb within Expertiza because it isn't called anywhere. We instead implemented unit tests that offer 100% coverage. We tested each of the four methods separately.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/CSC517-Project4/expertiza/blob/main/spec/models/view_translation_substitutor_spec.rb Link to Rspec Repository]&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
Implement view_translation_substitutor.rb in Expertiza to support internationalization.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/2800 Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156909</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156909"/>
		<updated>2024-04-24T23:24:11Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Model Overview &amp;amp; Test Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
We are unable to find anything that invokes this view_translation_subsitutor throughout the rest of the expertiza code base, so we have created unit tests to verify its functionality independently to ensure that it integrates smoothly with other modules without any issues.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
While implementing the view translation substitution functionality using the ViewTranslationSubstitutor class, the following design goals should be ensured:&lt;br /&gt;
&lt;br /&gt;
* '''Goal #1:''' Determine the purpose and invocation timing of view_translation_substitutor.rb to understand its role in the application's internationalization process and ensure proper integration with the existing codebase.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #2:''' Debug and fix the substitute() method to ensure it correctly processes the locale hash, generates accurate translation statistics, and writes them to the YAML file, handling any edge cases or error scenarios that may arise.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #3:''' Write comprehensive test cases for the key methods of the ViewTranslationSubstitutor class, including substitute, process_directory, process_view, and process_translation, to validate their correctness, robustness, and adherence to the expected behavior.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #4:''' Extend the test suite to cover edge cases and exceptional scenarios, such as empty or invalid locale hashes, missing view files or directories, translation keys with special characters, and performance testing with large or complex view files, ensuring the class handles these situations gracefully and maintains its reliability.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
''Parameters:'' locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# The class replaces hardcoded strings in view templates with translated versions according to the provided locale hash.&lt;br /&gt;
# The class keeps the content of the Expertiza application up-to-date with the latest translations, maintaining consistency and relevance in multiple languages.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#substitute' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  it 'iterates over the locale hash and processes directories' do&lt;br /&gt;
    # Create a sample locale hash.&lt;br /&gt;
    locale = {&lt;br /&gt;
      'dir1' =&amp;gt; { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } },&lt;br /&gt;
      'dir2' =&amp;gt; { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    # Expect process_directory to be called for each directory in the locale hash.&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir1', { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } }).and_return('stats1')&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir2', { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }).and_return('stats2')&lt;br /&gt;
&lt;br /&gt;
    # Expect File.open to be called with a regex matching translation_stats*.yml and write the processed stats to YAML.&lt;br /&gt;
    expect(File).to receive(:open).with(/^translation_stats.*\.yml$/, 'w').and_yield(file = double)&lt;br /&gt;
    expect(file).to receive(:write).with({ 'dir1' =&amp;gt; 'stats1', 'dir2' =&amp;gt; 'stats2' }.to_yaml)&lt;br /&gt;
&lt;br /&gt;
    # Call the substitute method with the sample locale hash.&lt;br /&gt;
    substitutor.substitute(locale)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model can ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When interacting with a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_directory' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is not empty' do&lt;br /&gt;
    let(:dir_name) { 'dir1' }&lt;br /&gt;
    let(:view_hash) { { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } } }&lt;br /&gt;
&lt;br /&gt;
    it 'processes each view in the view_hash' do&lt;br /&gt;
      # Stub process_view method to return 'stats1' and ensure it is called with correct arguments.&lt;br /&gt;
      allow(substitutor).to receive(:process_view).and_return('stats1')&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({ 'view1' =&amp;gt; 'stats1' })&lt;br /&gt;
      expect(substitutor).to have_received(:process_view).with(dir_name, 'view1', { 'key1' =&amp;gt; 'val1' })&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is empty' do&lt;br /&gt;
    # Local variables&lt;br /&gt;
    let(:dir_name) { 'dir2' }&lt;br /&gt;
    let(:view_hash) { {} }&lt;br /&gt;
&lt;br /&gt;
    it 'returns an empty hash' do&lt;br /&gt;
      # Call the private method process_directory with an empty view_hash and ensure it returns an empty hash.&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({})&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When interacting with a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file, then the display placeholders indicating missing translations.&lt;br /&gt;
# When the filenames begin with an underscore, the files should be handled as if they don't begin with an underscore.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_view' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
  let(:directory_name) { 'test_folder' }&lt;br /&gt;
  let(:view_name) { 'example_view' }&lt;br /&gt;
  let(:translations) { { 'key1' =&amp;gt; 'value1', 'key2' =&amp;gt; 'value2' } }&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return true and File.open to yield &amp;quot;Existing content&amp;quot;.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file does not exist' do&lt;br /&gt;
    it 'returns &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;' do&lt;br /&gt;
      # Call the process_view method and expect it to return &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq('&amp;lt;file not found&amp;gt;')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the alternate view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return false for main view file and true for alternate view file.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(false)&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the alternate file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the alternate view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model will incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When interacting with a marketer, the model will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file, then .&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_translation' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:contents) { 'This is a test string with some &amp;quot;text&amp;quot; to be replaced.' }&lt;br /&gt;
  let(:key) { 'other word' }&lt;br /&gt;
  let(:val) { 'text' }&lt;br /&gt;
  let(:key2) { 'skipped key' }&lt;br /&gt;
  let(:val2) { 'string' }&lt;br /&gt;
  let(:key3) { 'non-existent key' }&lt;br /&gt;
  let(:val3) { 'non-existent val' }&lt;br /&gt;
&lt;br /&gt;
  it 'replaces the correct text with translation keys' do&lt;br /&gt;
    # Call process_translation with a valid key and value and expect correct replacements and modified content.&lt;br /&gt;
    replacements, new_contents = substitutor.send(:process_translation, contents, key, val)&lt;br /&gt;
&lt;br /&gt;
    expect(replacements).to include(&amp;quot;replacements&amp;quot; =&amp;gt; [&amp;quot;\&amp;quot;#{val}\&amp;quot;&amp;quot;])&lt;br /&gt;
    expect(new_contents).to include(&amp;quot;#{key}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds to skip when one value is not found but another value is' do&lt;br /&gt;
    # Call process_translation with a key and value that partially match the contents and expect skips and unmodified content.&lt;br /&gt;
    skips, new_contents = substitutor.send(:process_translation, contents, key2, val2)&lt;br /&gt;
&lt;br /&gt;
    expect(skips).to include(&amp;quot;skips&amp;quot; =&amp;gt; [&amp;quot;test string with&amp;quot;])&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key2}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds &amp;lt;unmatched&amp;gt; to translation_stats when there is no match' do&lt;br /&gt;
    # Call process_translation with a key and value that do not match any part of the contents and expect &amp;lt;unmatched&amp;gt; and unmodified content.&lt;br /&gt;
    translation_stats, new_contents = substitutor.send(:process_translation, contents, key3, val3)&lt;br /&gt;
&lt;br /&gt;
    expect(translation_stats).to include(&amp;quot;&amp;lt;unmatched&amp;gt;&amp;quot;)&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key3}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video (Youtube)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[https://vimeo.com/938411539?share=copy Demo Video (Vimeo)]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We were unable to test view_translation_substitutor.rb within Expertiza because it isn't called anywhere. We instead implemented unit tests that offer 100% coverage. We tested each of the four methods separately.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/CSC517-Project4/expertiza/blob/main/spec/models/view_translation_substitutor_spec.rb Link to Rspec Repository]&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
Implement view_translation_substitutor.rb in Expertiza to support internationalization.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/2800 Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156908</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156908"/>
		<updated>2024-04-24T22:53:20Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Method Descriptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
We are unable to find anything that invokes this view_translation_subsitutor throughout the rest of the expertiza code base, so we have created unit tests to verify its functionality independently to ensure that it integrates smoothly with other modules without any issues.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
While implementing the view translation substitution functionality using the ViewTranslationSubstitutor class, the following design goals should be ensured:&lt;br /&gt;
&lt;br /&gt;
* '''Goal #1:''' Determine the purpose and invocation timing of view_translation_substitutor.rb to understand its role in the application's internationalization process and ensure proper integration with the existing codebase.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #2:''' Debug and fix the substitute() method to ensure it correctly processes the locale hash, generates accurate translation statistics, and writes them to the YAML file, handling any edge cases or error scenarios that may arise.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #3:''' Write comprehensive test cases for the key methods of the ViewTranslationSubstitutor class, including substitute, process_directory, process_view, and process_translation, to validate their correctness, robustness, and adherence to the expected behavior.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #4:''' Extend the test suite to cover edge cases and exceptional scenarios, such as empty or invalid locale hashes, missing view files or directories, translation keys with special characters, and performance testing with large or complex view files, ensuring the class handles these situations gracefully and maintains its reliability.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
''Parameters:'' locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# The class replaces hardcoded strings in view templates with translated versions according to the provided locale hash.&lt;br /&gt;
# The class keeps the content of the Expertiza application up-to-date with the latest translations, maintaining consistency and relevance in multiple languages.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#substitute' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  it 'iterates over the locale hash and processes directories' do&lt;br /&gt;
    # Create a sample locale hash.&lt;br /&gt;
    locale = {&lt;br /&gt;
      'dir1' =&amp;gt; { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } },&lt;br /&gt;
      'dir2' =&amp;gt; { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    # Expect process_directory to be called for each directory in the locale hash.&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir1', { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } }).and_return('stats1')&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir2', { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }).and_return('stats2')&lt;br /&gt;
&lt;br /&gt;
    # Expect File.open to be called with a regex matching translation_stats*.yml and write the processed stats to YAML.&lt;br /&gt;
    expect(File).to receive(:open).with(/^translation_stats.*\.yml$/, 'w').and_yield(file = double)&lt;br /&gt;
    expect(file).to receive(:write).with({ 'dir1' =&amp;gt; 'stats1', 'dir2' =&amp;gt; 'stats2' }.to_yaml)&lt;br /&gt;
&lt;br /&gt;
    # Call the substitute method with the sample locale hash.&lt;br /&gt;
    substitutor.substitute(locale)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model can ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When interacting with a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_directory' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is not empty' do&lt;br /&gt;
    let(:dir_name) { 'dir1' }&lt;br /&gt;
    let(:view_hash) { { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } } }&lt;br /&gt;
&lt;br /&gt;
    it 'processes each view in the view_hash' do&lt;br /&gt;
      # Stub process_view method to return 'stats1' and ensure it is called with correct arguments.&lt;br /&gt;
      allow(substitutor).to receive(:process_view).and_return('stats1')&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({ 'view1' =&amp;gt; 'stats1' })&lt;br /&gt;
      expect(substitutor).to have_received(:process_view).with(dir_name, 'view1', { 'key1' =&amp;gt; 'val1' })&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is empty' do&lt;br /&gt;
    # Local variables&lt;br /&gt;
    let(:dir_name) { 'dir2' }&lt;br /&gt;
    let(:view_hash) { {} }&lt;br /&gt;
&lt;br /&gt;
    it 'returns an empty hash' do&lt;br /&gt;
      # Call the private method process_directory with an empty view_hash and ensure it returns an empty hash.&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({})&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When interacting with a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the filenames begin with an underscore, the files should be handled as if they don't.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_view' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
  let(:directory_name) { 'test_folder' }&lt;br /&gt;
  let(:view_name) { 'example_view' }&lt;br /&gt;
  let(:translations) { { 'key1' =&amp;gt; 'value1', 'key2' =&amp;gt; 'value2' } }&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return true and File.open to yield &amp;quot;Existing content&amp;quot;.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file does not exist' do&lt;br /&gt;
    it 'returns &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;' do&lt;br /&gt;
      # Call the process_view method and expect it to return &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq('&amp;lt;file not found&amp;gt;')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the alternate view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return false for main view file and true for alternate view file.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(false)&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the alternate file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the alternate view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model will incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When interacting with a marketer, the model will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_translation' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:contents) { 'This is a test string with some &amp;quot;text&amp;quot; to be replaced.' }&lt;br /&gt;
  let(:key) { 'other word' }&lt;br /&gt;
  let(:val) { 'text' }&lt;br /&gt;
  let(:key2) { 'skipped key' }&lt;br /&gt;
  let(:val2) { 'string' }&lt;br /&gt;
  let(:key3) { 'non-existent key' }&lt;br /&gt;
  let(:val3) { 'non-existent val' }&lt;br /&gt;
&lt;br /&gt;
  it 'replaces the correct text with translation keys' do&lt;br /&gt;
    # Call process_translation with a valid key and value and expect correct replacements and modified content.&lt;br /&gt;
    replacements, new_contents = substitutor.send(:process_translation, contents, key, val)&lt;br /&gt;
&lt;br /&gt;
    expect(replacements).to include(&amp;quot;replacements&amp;quot; =&amp;gt; [&amp;quot;\&amp;quot;#{val}\&amp;quot;&amp;quot;])&lt;br /&gt;
    expect(new_contents).to include(&amp;quot;#{key}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds to skip when one value is not found but another value is' do&lt;br /&gt;
    # Call process_translation with a key and value that partially match the contents and expect skips and unmodified content.&lt;br /&gt;
    skips, new_contents = substitutor.send(:process_translation, contents, key2, val2)&lt;br /&gt;
&lt;br /&gt;
    expect(skips).to include(&amp;quot;skips&amp;quot; =&amp;gt; [&amp;quot;test string with&amp;quot;])&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key2}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds &amp;lt;unmatched&amp;gt; to translation_stats when there is no match' do&lt;br /&gt;
    # Call process_translation with a key and value that do not match any part of the contents and expect &amp;lt;unmatched&amp;gt; and unmodified content.&lt;br /&gt;
    translation_stats, new_contents = substitutor.send(:process_translation, contents, key3, val3)&lt;br /&gt;
&lt;br /&gt;
    expect(translation_stats).to include(&amp;quot;&amp;lt;unmatched&amp;gt;&amp;quot;)&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key3}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video (Youtube)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[https://vimeo.com/938411539?share=copy Demo Video (Vimeo)]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We were unable to test view_translation_substitutor.rb within Expertiza because it isn't called anywhere. We instead implemented unit tests that offer 100% coverage. We tested each of the four methods separately.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/CSC517-Project4/expertiza/blob/main/spec/models/view_translation_substitutor_spec.rb Link to Rspec Repository]&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
Implement view_translation_substitutor.rb in Expertiza to support internationalization.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/2800 Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156907</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156907"/>
		<updated>2024-04-24T22:51:50Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Method Descriptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
We are unable to find anything that invokes this view_translation_subsitutor throughout the rest of the expertiza code base, so we have created unit tests to verify its functionality independently to ensure that it integrates smoothly with other modules without any issues.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
While implementing the view translation substitution functionality using the ViewTranslationSubstitutor class, the following design goals should be ensured:&lt;br /&gt;
&lt;br /&gt;
* '''Goal #1:''' Determine the purpose and invocation timing of view_translation_substitutor.rb to understand its role in the application's internationalization process and ensure proper integration with the existing codebase.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #2:''' Debug and fix the substitute() method to ensure it correctly processes the locale hash, generates accurate translation statistics, and writes them to the YAML file, handling any edge cases or error scenarios that may arise.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #3:''' Write comprehensive test cases for the key methods of the ViewTranslationSubstitutor class, including substitute, process_directory, process_view, and process_translation, to validate their correctness, robustness, and adherence to the expected behavior.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #4:''' Extend the test suite to cover edge cases and exceptional scenarios, such as empty or invalid locale hashes, missing view files or directories, translation keys with special characters, and performance testing with large or complex view files, ensuring the class handles these situations gracefully and maintains its reliability.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
''Parameters:'' locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# The class replaces hardcoded strings in view templates with translated versions according to the provided locale hash.&lt;br /&gt;
# The class keeps the content of the Expertiza application up-to-date with the latest translations, maintaining consistency and relevance in multiple languages.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#substitute' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  it 'iterates over the locale hash and processes directories' do&lt;br /&gt;
    # Create a sample locale hash.&lt;br /&gt;
    locale = {&lt;br /&gt;
      'dir1' =&amp;gt; { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } },&lt;br /&gt;
      'dir2' =&amp;gt; { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    # Expect process_directory to be called for each directory in the locale hash.&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir1', { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } }).and_return('stats1')&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir2', { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }).and_return('stats2')&lt;br /&gt;
&lt;br /&gt;
    # Expect File.open to be called with a regex matching translation_stats*.yml and write the processed stats to YAML.&lt;br /&gt;
    expect(File).to receive(:open).with(/^translation_stats.*\.yml$/, 'w').and_yield(file = double)&lt;br /&gt;
    expect(file).to receive(:write).with({ 'dir1' =&amp;gt; 'stats1', 'dir2' =&amp;gt; 'stats2' }.to_yaml)&lt;br /&gt;
&lt;br /&gt;
    # Call the substitute method with the sample locale hash.&lt;br /&gt;
    substitutor.substitute(locale)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model can ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When interacting with a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_directory' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is not empty' do&lt;br /&gt;
    let(:dir_name) { 'dir1' }&lt;br /&gt;
    let(:view_hash) { { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } } }&lt;br /&gt;
&lt;br /&gt;
    it 'processes each view in the view_hash' do&lt;br /&gt;
      # Stub process_view method to return 'stats1' and ensure it is called with correct arguments.&lt;br /&gt;
      allow(substitutor).to receive(:process_view).and_return('stats1')&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({ 'view1' =&amp;gt; 'stats1' })&lt;br /&gt;
      expect(substitutor).to have_received(:process_view).with(dir_name, 'view1', { 'key1' =&amp;gt; 'val1' })&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is empty' do&lt;br /&gt;
    # Local variables&lt;br /&gt;
    let(:dir_name) { 'dir2' }&lt;br /&gt;
    let(:view_hash) { {} }&lt;br /&gt;
&lt;br /&gt;
    it 'returns an empty hash' do&lt;br /&gt;
      # Call the private method process_directory with an empty view_hash and ensure it returns an empty hash.&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({})&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When interacting with a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the filenames begin with an underscore, the files should be handled as if they don't.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_view' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
  let(:directory_name) { 'test_folder' }&lt;br /&gt;
  let(:view_name) { 'example_view' }&lt;br /&gt;
  let(:translations) { { 'key1' =&amp;gt; 'value1', 'key2' =&amp;gt; 'value2' } }&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return true and File.open to yield &amp;quot;Existing content&amp;quot;.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file does not exist' do&lt;br /&gt;
    it 'returns &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;' do&lt;br /&gt;
      # Call the process_view method and expect it to return &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq('&amp;lt;file not found&amp;gt;')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the alternate view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return false for main view file and true for alternate view file.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(false)&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the alternate file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the alternate view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model will incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When interacting with a marketer, the model will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_translation' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:contents) { 'This is a test string with some &amp;quot;text&amp;quot; to be replaced.' }&lt;br /&gt;
  let(:key) { 'other word' }&lt;br /&gt;
  let(:val) { 'text' }&lt;br /&gt;
  let(:key2) { 'skipped key' }&lt;br /&gt;
  let(:val2) { 'string' }&lt;br /&gt;
  let(:key3) { 'non-existent key' }&lt;br /&gt;
  let(:val3) { 'non-existent val' }&lt;br /&gt;
&lt;br /&gt;
  it 'replaces the correct text with translation keys' do&lt;br /&gt;
    # Call process_translation with a valid key and value and expect correct replacements and modified content.&lt;br /&gt;
    replacements, new_contents = substitutor.send(:process_translation, contents, key, val)&lt;br /&gt;
&lt;br /&gt;
    expect(replacements).to include(&amp;quot;replacements&amp;quot; =&amp;gt; [&amp;quot;\&amp;quot;#{val}\&amp;quot;&amp;quot;])&lt;br /&gt;
    expect(new_contents).to include(&amp;quot;#{key}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds to skip when one value is not found but another value is' do&lt;br /&gt;
    # Call process_translation with a key and value that partially match the contents and expect skips and unmodified content.&lt;br /&gt;
    skips, new_contents = substitutor.send(:process_translation, contents, key2, val2)&lt;br /&gt;
&lt;br /&gt;
    expect(skips).to include(&amp;quot;skips&amp;quot; =&amp;gt; [&amp;quot;test string with&amp;quot;])&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key2}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds &amp;lt;unmatched&amp;gt; to translation_stats when there is no match' do&lt;br /&gt;
    # Call process_translation with a key and value that do not match any part of the contents and expect &amp;lt;unmatched&amp;gt; and unmodified content.&lt;br /&gt;
    translation_stats, new_contents = substitutor.send(:process_translation, contents, key3, val3)&lt;br /&gt;
&lt;br /&gt;
    expect(translation_stats).to include(&amp;quot;&amp;lt;unmatched&amp;gt;&amp;quot;)&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key3}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video (Youtube)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[https://vimeo.com/938411539?share=copy Demo Video (Vimeo)]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We were unable to test view_translation_substitutor.rb within Expertiza because it isn't called anywhere. We instead implemented unit tests that offer 100% coverage. We tested each of the four methods separately.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/CSC517-Project4/expertiza/blob/main/spec/models/view_translation_substitutor_spec.rb Link to Rspec Repository]&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
Implement view_translation_substitutor.rb in Expertiza to support internationalization.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/2800 Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156906</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156906"/>
		<updated>2024-04-24T22:48:27Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Model Overview &amp;amp; Test Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
We are unable to find anything that invokes this view_translation_subsitutor throughout the rest of the expertiza code base, so we have created unit tests to verify its functionality independently to ensure that it integrates smoothly with other modules without any issues.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
While implementing the view translation substitution functionality using the ViewTranslationSubstitutor class, the following design goals should be ensured:&lt;br /&gt;
&lt;br /&gt;
* '''Goal #1:''' Determine the purpose and invocation timing of view_translation_substitutor.rb to understand its role in the application's internationalization process and ensure proper integration with the existing codebase.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #2:''' Debug and fix the substitute() method to ensure it correctly processes the locale hash, generates accurate translation statistics, and writes them to the YAML file, handling any edge cases or error scenarios that may arise.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #3:''' Write comprehensive test cases for the key methods of the ViewTranslationSubstitutor class, including substitute, process_directory, process_view, and process_translation, to validate their correctness, robustness, and adherence to the expected behavior.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #4:''' Extend the test suite to cover edge cases and exceptional scenarios, such as empty or invalid locale hashes, missing view files or directories, translation keys with special characters, and performance testing with large or complex view files, ensuring the class handles these situations gracefully and maintains its reliability.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
''Parameters:'' locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# The class replaces hardcoded strings in view templates with translated versions according to the provided locale hash.&lt;br /&gt;
# The class keeps the content of the Expertiza application up-to-date with the latest translations, maintaining consistency and relevance in multiple languages.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#substitute' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  it 'iterates over the locale hash and processes directories' do&lt;br /&gt;
    # Create a sample locale hash.&lt;br /&gt;
    locale = {&lt;br /&gt;
      'dir1' =&amp;gt; { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } },&lt;br /&gt;
      'dir2' =&amp;gt; { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    # Expect process_directory to be called for each directory in the locale hash.&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir1', { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } }).and_return('stats1')&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir2', { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }).and_return('stats2')&lt;br /&gt;
&lt;br /&gt;
    # Expect File.open to be called with a regex matching translation_stats*.yml and write the processed stats to YAML.&lt;br /&gt;
    expect(File).to receive(:open).with(/^translation_stats.*\.yml$/, 'w').and_yield(file = double)&lt;br /&gt;
    expect(file).to receive(:write).with({ 'dir1' =&amp;gt; 'stats1', 'dir2' =&amp;gt; 'stats2' }.to_yaml)&lt;br /&gt;
&lt;br /&gt;
    # Call the substitute method with the sample locale hash.&lt;br /&gt;
    substitutor.substitute(locale)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When interacting with a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_directory' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is not empty' do&lt;br /&gt;
    let(:dir_name) { 'dir1' }&lt;br /&gt;
    let(:view_hash) { { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } } }&lt;br /&gt;
&lt;br /&gt;
    it 'processes each view in the view_hash' do&lt;br /&gt;
      # Stub process_view method to return 'stats1' and ensure it is called with correct arguments.&lt;br /&gt;
      allow(substitutor).to receive(:process_view).and_return('stats1')&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({ 'view1' =&amp;gt; 'stats1' })&lt;br /&gt;
      expect(substitutor).to have_received(:process_view).with(dir_name, 'view1', { 'key1' =&amp;gt; 'val1' })&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is empty' do&lt;br /&gt;
    # Local variables&lt;br /&gt;
    let(:dir_name) { 'dir2' }&lt;br /&gt;
    let(:view_hash) { {} }&lt;br /&gt;
&lt;br /&gt;
    it 'returns an empty hash' do&lt;br /&gt;
      # Call the private method process_directory with an empty view_hash and ensure it returns an empty hash.&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({})&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When interacting with a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the filenames begin with an underscore, the files should be handled as if they don't.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_view' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
  let(:directory_name) { 'test_folder' }&lt;br /&gt;
  let(:view_name) { 'example_view' }&lt;br /&gt;
  let(:translations) { { 'key1' =&amp;gt; 'value1', 'key2' =&amp;gt; 'value2' } }&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return true and File.open to yield &amp;quot;Existing content&amp;quot;.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file does not exist' do&lt;br /&gt;
    it 'returns &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;' do&lt;br /&gt;
      # Call the process_view method and expect it to return &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq('&amp;lt;file not found&amp;gt;')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the alternate view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return false for main view file and true for alternate view file.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(false)&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the alternate file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the alternate view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When interacting with a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When interacting with a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_translation' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:contents) { 'This is a test string with some &amp;quot;text&amp;quot; to be replaced.' }&lt;br /&gt;
  let(:key) { 'other word' }&lt;br /&gt;
  let(:val) { 'text' }&lt;br /&gt;
  let(:key2) { 'skipped key' }&lt;br /&gt;
  let(:val2) { 'string' }&lt;br /&gt;
  let(:key3) { 'non-existent key' }&lt;br /&gt;
  let(:val3) { 'non-existent val' }&lt;br /&gt;
&lt;br /&gt;
  it 'replaces the correct text with translation keys' do&lt;br /&gt;
    # Call process_translation with a valid key and value and expect correct replacements and modified content.&lt;br /&gt;
    replacements, new_contents = substitutor.send(:process_translation, contents, key, val)&lt;br /&gt;
&lt;br /&gt;
    expect(replacements).to include(&amp;quot;replacements&amp;quot; =&amp;gt; [&amp;quot;\&amp;quot;#{val}\&amp;quot;&amp;quot;])&lt;br /&gt;
    expect(new_contents).to include(&amp;quot;#{key}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds to skip when one value is not found but another value is' do&lt;br /&gt;
    # Call process_translation with a key and value that partially match the contents and expect skips and unmodified content.&lt;br /&gt;
    skips, new_contents = substitutor.send(:process_translation, contents, key2, val2)&lt;br /&gt;
&lt;br /&gt;
    expect(skips).to include(&amp;quot;skips&amp;quot; =&amp;gt; [&amp;quot;test string with&amp;quot;])&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key2}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds &amp;lt;unmatched&amp;gt; to translation_stats when there is no match' do&lt;br /&gt;
    # Call process_translation with a key and value that do not match any part of the contents and expect &amp;lt;unmatched&amp;gt; and unmodified content.&lt;br /&gt;
    translation_stats, new_contents = substitutor.send(:process_translation, contents, key3, val3)&lt;br /&gt;
&lt;br /&gt;
    expect(translation_stats).to include(&amp;quot;&amp;lt;unmatched&amp;gt;&amp;quot;)&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key3}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video (Youtube)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[https://vimeo.com/938411539?share=copy Demo Video (Vimeo)]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We were unable to test view_translation_substitutor.rb within Expertiza because it isn't called anywhere. We instead implemented unit tests that offer 100% coverage. We tested each of the four methods separately.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/CSC517-Project4/expertiza/blob/main/spec/models/view_translation_substitutor_spec.rb Link to Rspec Repository]&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
Implement view_translation_substitutor.rb in Expertiza to support internationalization.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/2800 Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156355</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156355"/>
		<updated>2024-04-24T00:38:13Z</updated>

		<summary type="html">&lt;p&gt;Samason4: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
While implementing the view translation substitution functionality using the ViewTranslationSubstitutor class, the following design goals should be ensured:&lt;br /&gt;
&lt;br /&gt;
* '''Goal #1:''' Determine the purpose and invocation timing of view_translation_substitutor.rb to understand its role in the application's internationalization process and ensure proper integration with the existing codebase.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #2:''' Debug and fix the substitute() method to ensure it correctly processes the locale hash, generates accurate translation statistics, and writes them to the YAML file, handling any edge cases or error scenarios that may arise.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #3:''' Write comprehensive test cases for the key methods of the ViewTranslationSubstitutor class, including substitute, process_directory, process_view, and process_translation, to validate their correctness, robustness, and adherence to the expected behavior.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #4:''' Extend the test suite to cover edge cases and exceptional scenarios, such as empty or invalid locale hashes, missing view files or directories, translation keys with special characters, and performance testing with large or complex view files, ensuring the class handles these situations gracefully and maintains its reliability.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#substitute' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  it 'iterates over the locale hash and processes directories' do&lt;br /&gt;
    # Create a sample locale hash.&lt;br /&gt;
    locale = {&lt;br /&gt;
      'dir1' =&amp;gt; { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } },&lt;br /&gt;
      'dir2' =&amp;gt; { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    # Expect process_directory to be called for each directory in the locale hash.&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir1', { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } }).and_return('stats1')&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir2', { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }).and_return('stats2')&lt;br /&gt;
&lt;br /&gt;
    # Expect File.open to be called with a regex matching translation_stats*.yml and write the processed stats to YAML.&lt;br /&gt;
    expect(File).to receive(:open).with(/^translation_stats.*\.yml$/, 'w').and_yield(file = double)&lt;br /&gt;
    expect(file).to receive(:write).with({ 'dir1' =&amp;gt; 'stats1', 'dir2' =&amp;gt; 'stats2' }.to_yaml)&lt;br /&gt;
&lt;br /&gt;
    # Call the substitute method with the sample locale hash.&lt;br /&gt;
    substitutor.substitute(locale)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_directory' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is not empty' do&lt;br /&gt;
    let(:dir_name) { 'dir1' }&lt;br /&gt;
    let(:view_hash) { { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } } }&lt;br /&gt;
&lt;br /&gt;
    it 'processes each view in the view_hash' do&lt;br /&gt;
      # Stub process_view method to return 'stats1' and ensure it is called with correct arguments.&lt;br /&gt;
      allow(substitutor).to receive(:process_view).and_return('stats1')&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({ 'view1' =&amp;gt; 'stats1' })&lt;br /&gt;
      expect(substitutor).to have_received(:process_view).with(dir_name, 'view1', { 'key1' =&amp;gt; 'val1' })&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is empty' do&lt;br /&gt;
    # Local variables&lt;br /&gt;
    let(:dir_name) { 'dir2' }&lt;br /&gt;
    let(:view_hash) { {} }&lt;br /&gt;
&lt;br /&gt;
    it 'returns an empty hash' do&lt;br /&gt;
      # Call the private method process_directory with an empty view_hash and ensure it returns an empty hash.&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({})&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_view' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
  let(:directory_name) { 'test_folder' }&lt;br /&gt;
  let(:view_name) { 'example_view' }&lt;br /&gt;
  let(:translations) { { 'key1' =&amp;gt; 'value1', 'key2' =&amp;gt; 'value2' } }&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return true and File.open to yield &amp;quot;Existing content&amp;quot;.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file does not exist' do&lt;br /&gt;
    it 'returns &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;' do&lt;br /&gt;
      # Call the process_view method and expect it to return &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq('&amp;lt;file not found&amp;gt;')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the alternate view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return false for main view file and true for alternate view file.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(false)&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the alternate file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the alternate view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_translation' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:contents) { 'This is a test string with some &amp;quot;text&amp;quot; to be replaced.' }&lt;br /&gt;
  let(:key) { 'other word' }&lt;br /&gt;
  let(:val) { 'text' }&lt;br /&gt;
  let(:key2) { 'skipped key' }&lt;br /&gt;
  let(:val2) { 'string' }&lt;br /&gt;
  let(:key3) { 'non-existent key' }&lt;br /&gt;
  let(:val3) { 'non-existent val' }&lt;br /&gt;
&lt;br /&gt;
  it 'replaces the correct text with translation keys' do&lt;br /&gt;
    # Call process_translation with a valid key and value and expect correct replacements and modified content.&lt;br /&gt;
    replacements, new_contents = substitutor.send(:process_translation, contents, key, val)&lt;br /&gt;
&lt;br /&gt;
    expect(replacements).to include(&amp;quot;replacements&amp;quot; =&amp;gt; [&amp;quot;\&amp;quot;#{val}\&amp;quot;&amp;quot;])&lt;br /&gt;
    expect(new_contents).to include(&amp;quot;#{key}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds to skip when one value is not found but another value is' do&lt;br /&gt;
    # Call process_translation with a key and value that partially match the contents and expect skips and unmodified content.&lt;br /&gt;
    skips, new_contents = substitutor.send(:process_translation, contents, key2, val2)&lt;br /&gt;
&lt;br /&gt;
    expect(skips).to include(&amp;quot;skips&amp;quot; =&amp;gt; [&amp;quot;test string with&amp;quot;])&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key2}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds &amp;lt;unmatched&amp;gt; to translation_stats when there is no match' do&lt;br /&gt;
    # Call process_translation with a key and value that do not match any part of the contents and expect &amp;lt;unmatched&amp;gt; and unmodified content.&lt;br /&gt;
    translation_stats, new_contents = substitutor.send(:process_translation, contents, key3, val3)&lt;br /&gt;
&lt;br /&gt;
    expect(translation_stats).to include(&amp;quot;&amp;lt;unmatched&amp;gt;&amp;quot;)&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key3}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video (Youtube)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[https://vimeo.com/938411539?share=copy Demo Video (Vimeo)]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
Implement view_translation_substitutor.rb in Expertiza to support internationalization.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/2800 Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156354</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156354"/>
		<updated>2024-04-24T00:37:59Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
While implementing the view translation substitution functionality using the ViewTranslationSubstitutor class, the following design goals should be ensured:&lt;br /&gt;
&lt;br /&gt;
* '''Goal #1:''' Determine the purpose and invocation timing of view_translation_substitutor.rb to understand its role in the application's internationalization process and ensure proper integration with the existing codebase.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #2:''' Debug and fix the substitute() method to ensure it correctly processes the locale hash, generates accurate translation statistics, and writes them to the YAML file, handling any edge cases or error scenarios that may arise.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #3:''' Write comprehensive test cases for the key methods of the ViewTranslationSubstitutor class, including substitute, process_directory, process_view, and process_translation, to validate their correctness, robustness, and adherence to the expected behavior.&lt;br /&gt;
&lt;br /&gt;
* '''Goal #4:''' Extend the test suite to cover edge cases and exceptional scenarios, such as empty or invalid locale hashes, missing view files or directories, translation keys with special characters, and performance testing with large or complex view files, ensuring the class handles these situations gracefully and maintains its reliability.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#substitute' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  it 'iterates over the locale hash and processes directories' do&lt;br /&gt;
    # Create a sample locale hash.&lt;br /&gt;
    locale = {&lt;br /&gt;
      'dir1' =&amp;gt; { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } },&lt;br /&gt;
      'dir2' =&amp;gt; { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    # Expect process_directory to be called for each directory in the locale hash.&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir1', { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } }).and_return('stats1')&lt;br /&gt;
    expect(substitutor).to receive(:process_directory).with('dir2', { 'view2' =&amp;gt; { 'key2' =&amp;gt; 'val2' } }).and_return('stats2')&lt;br /&gt;
&lt;br /&gt;
    # Expect File.open to be called with a regex matching translation_stats*.yml and write the processed stats to YAML.&lt;br /&gt;
    expect(File).to receive(:open).with(/^translation_stats.*\.yml$/, 'w').and_yield(file = double)&lt;br /&gt;
    expect(file).to receive(:write).with({ 'dir1' =&amp;gt; 'stats1', 'dir2' =&amp;gt; 'stats2' }.to_yaml)&lt;br /&gt;
&lt;br /&gt;
    # Call the substitute method with the sample locale hash.&lt;br /&gt;
    substitutor.substitute(locale)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_directory' do&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is not empty' do&lt;br /&gt;
    let(:dir_name) { 'dir1' }&lt;br /&gt;
    let(:view_hash) { { 'view1' =&amp;gt; { 'key1' =&amp;gt; 'val1' } } }&lt;br /&gt;
&lt;br /&gt;
    it 'processes each view in the view_hash' do&lt;br /&gt;
      # Stub process_view method to return 'stats1' and ensure it is called with correct arguments.&lt;br /&gt;
      allow(substitutor).to receive(:process_view).and_return('stats1')&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({ 'view1' =&amp;gt; 'stats1' })&lt;br /&gt;
      expect(substitutor).to have_received(:process_view).with(dir_name, 'view1', { 'key1' =&amp;gt; 'val1' })&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when view_hash is empty' do&lt;br /&gt;
    # Local variables&lt;br /&gt;
    let(:dir_name) { 'dir2' }&lt;br /&gt;
    let(:view_hash) { {} }&lt;br /&gt;
&lt;br /&gt;
    it 'returns an empty hash' do&lt;br /&gt;
      # Call the private method process_directory with an empty view_hash and ensure it returns an empty hash.&lt;br /&gt;
      dir_stats = substitutor.send(:process_directory, dir_name, view_hash)&lt;br /&gt;
      expect(dir_stats).to eq({})&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_view' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:substitutor) { ViewTranslationSubstitutor.new }&lt;br /&gt;
  let(:directory_name) { 'test_folder' }&lt;br /&gt;
  let(:view_name) { 'example_view' }&lt;br /&gt;
  let(:translations) { { 'key1' =&amp;gt; 'value1', 'key2' =&amp;gt; 'value2' } }&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return true and File.open to yield &amp;quot;Existing content&amp;quot;.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the view file does not exist' do&lt;br /&gt;
    it 'returns &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;' do&lt;br /&gt;
      # Call the process_view method and expect it to return &amp;quot;&amp;lt;file not found&amp;gt;&amp;quot;.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
      expect(view_stats).to eq('&amp;lt;file not found&amp;gt;')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  context 'when the alternate view file exists' do&lt;br /&gt;
    before do&lt;br /&gt;
      # Stub File.exist? to return false for main view file and true for alternate view file.&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/#{view_name}.html.erb&amp;quot;).and_return(false)&lt;br /&gt;
      allow(File).to receive(:exist?).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;).and_return(true)&lt;br /&gt;
      allow(File).to receive(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').and_yield(StringIO.new(&amp;quot;Existing content&amp;quot;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'reads the alternate file, processes translations, and writes back the contents' do&lt;br /&gt;
      # Expect process_translation to be called for each translation and return modified content and stats.&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with(&amp;quot;Existing content&amp;quot;, 'key1', 'value1').and_return(['stats1', 'new_content1'])&lt;br /&gt;
      expect(substitutor).to receive(:process_translation).with('new_content1', 'key2', 'value2').and_return(['stats2', 'new_content2'])&lt;br /&gt;
&lt;br /&gt;
      # Call the process_view method and expect it to return processed view stats.&lt;br /&gt;
      view_stats = substitutor.send(:process_view, directory_name, view_name, translations)&lt;br /&gt;
&lt;br /&gt;
      expect(view_stats).to eq({ 'key1' =&amp;gt; 'stats1', 'key2' =&amp;gt; 'stats2' })&lt;br /&gt;
&lt;br /&gt;
      # Expect File.open to be called twice with the alternate view file path.&lt;br /&gt;
      expect(File).to have_received(:open).with(&amp;quot;./#{directory_name}/_#{view_name}.html.erb&amp;quot;, 'w').twice&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#process_translation' do&lt;br /&gt;
  # Local variables&lt;br /&gt;
  let(:contents) { 'This is a test string with some &amp;quot;text&amp;quot; to be replaced.' }&lt;br /&gt;
  let(:key) { 'other word' }&lt;br /&gt;
  let(:val) { 'text' }&lt;br /&gt;
  let(:key2) { 'skipped key' }&lt;br /&gt;
  let(:val2) { 'string' }&lt;br /&gt;
  let(:key3) { 'non-existent key' }&lt;br /&gt;
  let(:val3) { 'non-existent val' }&lt;br /&gt;
&lt;br /&gt;
  it 'replaces the correct text with translation keys' do&lt;br /&gt;
    # Call process_translation with a valid key and value and expect correct replacements and modified content.&lt;br /&gt;
    replacements, new_contents = substitutor.send(:process_translation, contents, key, val)&lt;br /&gt;
&lt;br /&gt;
    expect(replacements).to include(&amp;quot;replacements&amp;quot; =&amp;gt; [&amp;quot;\&amp;quot;#{val}\&amp;quot;&amp;quot;])&lt;br /&gt;
    expect(new_contents).to include(&amp;quot;#{key}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds to skip when one value is not found but another value is' do&lt;br /&gt;
    # Call process_translation with a key and value that partially match the contents and expect skips and unmodified content.&lt;br /&gt;
    skips, new_contents = substitutor.send(:process_translation, contents, key2, val2)&lt;br /&gt;
&lt;br /&gt;
    expect(skips).to include(&amp;quot;skips&amp;quot; =&amp;gt; [&amp;quot;test string with&amp;quot;])&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key2}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  it 'adds &amp;lt;unmatched&amp;gt; to translation_stats when there is no match' do&lt;br /&gt;
    # Call process_translation with a key and value that do not match any part of the contents and expect &amp;lt;unmatched&amp;gt; and unmodified content.&lt;br /&gt;
    translation_stats, new_contents = substitutor.send(:process_translation, contents, key3, val3)&lt;br /&gt;
&lt;br /&gt;
    expect(translation_stats).to include(&amp;quot;&amp;lt;unmatched&amp;gt;&amp;quot;)&lt;br /&gt;
    expect(new_contents).not_to include(&amp;quot;#{key3}&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video (Youtube)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[https://vimeo.com/938411539?share=copy Demo Video (Vimeo)]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
Implement view_translation_substitutor.rb in Expertiza to support internationalization.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/2800 Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156344</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=156344"/>
		<updated>2024-04-24T00:33:51Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review mappings imported.png|700px]]&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video (Youtube)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[https://vimeo.com/938411539?share=copy Demo Video (Vimeo)]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/2800 Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155810</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155810"/>
		<updated>2024-04-22T17:26:48Z</updated>

		<summary type="html">&lt;p&gt;Samason4: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review mappings imported.png|700px]]&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155809</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155809"/>
		<updated>2024-04-22T17:26:41Z</updated>

		<summary type="html">&lt;p&gt;Samason4: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review mappings imported.png|700px]]&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155808</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155808"/>
		<updated>2024-04-22T17:25:44Z</updated>

		<summary type="html">&lt;p&gt;Samason4: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155807</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155807"/>
		<updated>2024-04-22T17:24:36Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Files Modified */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substitutor_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155806</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155806"/>
		<updated>2024-04-22T17:24:11Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Files Modified */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substituto_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155805</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155805"/>
		<updated>2024-04-22T17:23:35Z</updated>

		<summary type="html">&lt;p&gt;Samason4: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb app/models/view_translation_substitutor.rb]&lt;br /&gt;
*  https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb app/spec/models/view_translation_substituto_spec.rb]&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155803</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155803"/>
		<updated>2024-04-22T17:21:09Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Plan of Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then, we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155802</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155802"/>
		<updated>2024-04-22T17:20:54Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Plan of Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155801</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155801"/>
		<updated>2024-04-22T17:20:01Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Plan of Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
[[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155800</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155800"/>
		<updated>2024-04-22T17:16:41Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Method Summaries */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Descriptions===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155799</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155799"/>
		<updated>2024-04-22T17:16:30Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Method Summaries: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Summaries===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155798</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155798"/>
		<updated>2024-04-22T17:16:18Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Model Overview &amp;amp; Test Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
===Method Summaries:===&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155797</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155797"/>
		<updated>2024-04-22T17:15:32Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file ([https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb]), some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155796</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155796"/>
		<updated>2024-04-22T17:14:51Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Project Objective */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various use and edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155795</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155795"/>
		<updated>2024-04-22T17:14:31Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Project Objective */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests in [https://github.com/CSC517-Project4/expertiza/blob/dev/spec/models/view_translation_substitutor_spec.rb view_translation_substitutor_spec.rb] to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155794</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155794"/>
		<updated>2024-04-22T17:11:42Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for [https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb] started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155792</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155792"/>
		<updated>2024-04-22T17:11:19Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Project Objective */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class ([https://github.com/CSC517-Project4/expertiza/blob/dev/app/models/view_translation_substitutor.rb view_translation_substitutor.rb]) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155790</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155790"/>
		<updated>2024-04-22T17:08:33Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently started at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155789</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155789"/>
		<updated>2024-04-22T17:07:17Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155787</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155787"/>
		<updated>2024-04-22T17:06:53Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
#Enhance the diversity of use case scenarios.&lt;br /&gt;
#Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155785</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155785"/>
		<updated>2024-04-22T17:06:17Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155784</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155784"/>
		<updated>2024-04-22T17:06:11Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
1. Enhance the diversity of use case scenarios.&lt;br /&gt;
2. Implement similar test for functionality linked to the view translation substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155782</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155782"/>
		<updated>2024-04-22T17:03:41Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
* Develop more use cases &lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155780</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155780"/>
		<updated>2024-04-22T17:02:50Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 700px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155779</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155779"/>
		<updated>2024-04-22T17:02:41Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 600px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155778</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155778"/>
		<updated>2024-04-22T17:02:30Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 500px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155777</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155777"/>
		<updated>2024-04-22T17:02:23Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png | 600px]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155776</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155776"/>
		<updated>2024-04-22T17:01:58Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* How to See Test Coverage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155775</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155775"/>
		<updated>2024-04-22T17:01:48Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* How to See Test Coverage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
*Note: We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155774</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155774"/>
		<updated>2024-04-22T17:01:34Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Test coverage is currently at 100%. We have written tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then, we added tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
[https://www.youtube.com/watch?v=C-fbMNsrTP8 Demo Video]&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
[[File:2439cov.png]]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155702</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155702"/>
		<updated>2024-04-19T17:09:32Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [https://github.com/orgs/CSC517-Project4/projects/1 Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155409</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155409"/>
		<updated>2024-04-09T01:23:04Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* How to See Test Coverage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for view_translation_substitutor.rb, &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155408</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155408"/>
		<updated>2024-04-09T01:22:49Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Using RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests which offers 100% coverage for the view_translation_substitutor.rb.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for [], &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155407</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155407"/>
		<updated>2024-04-09T01:21:03Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Model Overview &amp;amp; Test Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When translation files are located within nested directories, all directories should be recursively traverse to ensure that no translations are missed.&lt;br /&gt;
# When there are various file types (JSON, YAML, or plain text files), it should handle different file formats and parsing methods.  &lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they ensure consistent handling of translations across different parts of Expertiza.&lt;br /&gt;
# When it is a developer, the model can be integrated into workflows that utilize TMS platforms for managing translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the model encounters directories or files with restricted permissions or inaccessible locations, there must be proper error handling.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model localizes static text elements while preserving dynamic content.&lt;br /&gt;
# When it is a developer, the model will update view files with specific messaging and translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the translations parameter is empty or contains no translations for the specified view file.&lt;br /&gt;
# When the view file contains ambiguous strings that may have multiple possible translations.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, they will leverage the model to incorporate accessibility-focused translations and alternative text descriptions into view files for images, buttons, and other interactive elements.&lt;br /&gt;
# When it is a marketer, they will implement A/B test variations by dynamically swapping out hardcoded strings with alternative translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When the contents parameter contains invalid markup, preventing proper parsing of the view file.&lt;br /&gt;
# When the view file contains complex HTML structure with nested elements and dynamic content.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests in [] which offers 100% coverage for the view_translation_substitutor.rb Model.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for [], &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155314</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155314"/>
		<updated>2024-04-09T00:32:34Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Model Overview &amp;amp; Test Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When it is a developer, the model will replace hardcoded strings with translated versions.&lt;br /&gt;
# When it is a developer, Expertiza's content will always up-to-date with the latest translations.&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Design Patterns &amp;amp; Principles==&lt;br /&gt;
'''Single Responsibility Principle (SRP)''':&lt;br /&gt;
* Each test case has a single responsibility and focuses on a specific aspect of the application.&lt;br /&gt;
* The different types of tests (unit, integration, and system) are separated in order to improve clarity and organization.&lt;br /&gt;
&lt;br /&gt;
'''Don't Repeat Yourself  Principle (DRY)''':&lt;br /&gt;
* Setup and cleanup steps for all tests are the same and thus, are combined together.&lt;br /&gt;
&lt;br /&gt;
'''Open/Closed Principle (OCP)''':&lt;br /&gt;
* Test classes are designed so that they are open for extension. New tests can be added without needing to modify the existing test code.&lt;br /&gt;
&lt;br /&gt;
'''Singleton Pattern''':&lt;br /&gt;
* There is only a single setup that is shared for all of the test cases that need to use it.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests in [] which offers 100% coverage for the view_translation_substitutor.rb Model.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for [], &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155270</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155270"/>
		<updated>2024-04-09T00:11:08Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Task #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Task #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Task #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
Not sure what to put here. Below is an example from another project.&lt;br /&gt;
&lt;br /&gt;
The Code present in review_mapping_helper can be improved by using design patterns to improve maintainability, readability, and flexibility.&lt;br /&gt;
Following are some design patterns that are suggested &lt;br /&gt;
&lt;br /&gt;
* Methods can be extracted into smaller, well maintained with just a single responsibility. This will promote code readability and promote code reuse.&lt;br /&gt;
&lt;br /&gt;
*The methods review_report_data, team_color, obtain_team_color, and others follow a common sequence of steps but allow for variation in some steps. Applying the Template Method Pattern can help define a common structure in a base method while allowing specific steps to be implemented in subclasses or overridden in derived methods.&lt;br /&gt;
&lt;br /&gt;
*Descriptive and short naming conventions are required so the methods and variables are self explanatory.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns should be followed for following code.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests in [] which offers 100% coverage for the view_translation_substitutor.rb Model.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for [], &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155267</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155267"/>
		<updated>2024-04-09T00:10:17Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* How to See Test Coverage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
Not sure what to put here. Below is an example from another project.&lt;br /&gt;
&lt;br /&gt;
The Code present in review_mapping_helper can be improved by using design patterns to improve maintainability, readability, and flexibility.&lt;br /&gt;
Following are some design patterns that are suggested &lt;br /&gt;
&lt;br /&gt;
* Methods can be extracted into smaller, well maintained with just a single responsibility. This will promote code readability and promote code reuse.&lt;br /&gt;
&lt;br /&gt;
*The methods review_report_data, team_color, obtain_team_color, and others follow a common sequence of steps but allow for variation in some steps. Applying the Template Method Pattern can help define a common structure in a base method while allowing specific steps to be implemented in subclasses or overridden in derived methods.&lt;br /&gt;
&lt;br /&gt;
*Descriptive and short naming conventions are required so the methods and variables are self explanatory.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns should be followed for following code.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests in [] which offers 100% coverage for the view_translation_substitutor.rb Model.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for [], &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;. We chose to use Lynx because it displays the test coverage in an easy and readable way.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155265</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155265"/>
		<updated>2024-04-09T00:09:11Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Using RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
Not sure what to put here. Below is an example from another project.&lt;br /&gt;
&lt;br /&gt;
The Code present in review_mapping_helper can be improved by using design patterns to improve maintainability, readability, and flexibility.&lt;br /&gt;
Following are some design patterns that are suggested &lt;br /&gt;
&lt;br /&gt;
* Methods can be extracted into smaller, well maintained with just a single responsibility. This will promote code readability and promote code reuse.&lt;br /&gt;
&lt;br /&gt;
*The methods review_report_data, team_color, obtain_team_color, and others follow a common sequence of steps but allow for variation in some steps. Applying the Template Method Pattern can help define a common structure in a base method while allowing specific steps to be implemented in subclasses or overridden in derived methods.&lt;br /&gt;
&lt;br /&gt;
*Descriptive and short naming conventions are required so the methods and variables are self explanatory.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns should be followed for following code.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests in [] which offers 100% coverage for the view_translation_substitutor.rb Model.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for [], &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155264</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155264"/>
		<updated>2024-04-09T00:08:55Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
Not sure what to put here. Below is an example from another project.&lt;br /&gt;
&lt;br /&gt;
The Code present in review_mapping_helper can be improved by using design patterns to improve maintainability, readability, and flexibility.&lt;br /&gt;
Following are some design patterns that are suggested &lt;br /&gt;
&lt;br /&gt;
* Methods can be extracted into smaller, well maintained with just a single responsibility. This will promote code readability and promote code reuse.&lt;br /&gt;
&lt;br /&gt;
*The methods review_report_data, team_color, obtain_team_color, and others follow a common sequence of steps but allow for variation in some steps. Applying the Template Method Pattern can help define a common structure in a base method while allowing specific steps to be implemented in subclasses or overridden in derived methods.&lt;br /&gt;
&lt;br /&gt;
*Descriptive and short naming conventions are required so the methods and variables are self explanatory.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns should be followed for following code.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests in [] which offers 100% coverage for the XXX Controller.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for [], &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
view_translation_substitutor.rb model coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155262</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155262"/>
		<updated>2024-04-09T00:08:12Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Work Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
Not sure what to put here. Below is an example from another project.&lt;br /&gt;
&lt;br /&gt;
The Code present in review_mapping_helper can be improved by using design patterns to improve maintainability, readability, and flexibility.&lt;br /&gt;
Following are some design patterns that are suggested &lt;br /&gt;
&lt;br /&gt;
* Methods can be extracted into smaller, well maintained with just a single responsibility. This will promote code readability and promote code reuse.&lt;br /&gt;
&lt;br /&gt;
*The methods review_report_data, team_color, obtain_team_color, and others follow a common sequence of steps but allow for variation in some steps. Applying the Template Method Pattern can help define a common structure in a base method while allowing specific steps to be implemented in subclasses or overridden in derived methods.&lt;br /&gt;
&lt;br /&gt;
*Descriptive and short naming conventions are required so the methods and variables are self explanatory.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns should be followed for following code.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests in [] which offers 100% coverage for the XXX Controller.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for [], &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
XXX controller coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155260</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155260"/>
		<updated>2024-04-09T00:06:21Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Model Overview &amp;amp; Test Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
Not sure what to put here. Below is an example from another project.&lt;br /&gt;
&lt;br /&gt;
The Code present in review_mapping_helper can be improved by using design patterns to improve maintainability, readability, and flexibility.&lt;br /&gt;
Following are some design patterns that are suggested &lt;br /&gt;
&lt;br /&gt;
* Methods can be extracted into smaller, well maintained with just a single responsibility. This will promote code readability and promote code reuse.&lt;br /&gt;
&lt;br /&gt;
*The methods review_report_data, team_color, obtain_team_color, and others follow a common sequence of steps but allow for variation in some steps. Applying the Template Method Pattern can help define a common structure in a base method while allowing specific steps to be implemented in subclasses or overridden in derived methods.&lt;br /&gt;
&lt;br /&gt;
*Descriptive and short naming conventions are required so the methods and variables are self explanatory.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns should be followed for following code.&lt;br /&gt;
&lt;br /&gt;
====Work Plan====&lt;br /&gt;
&lt;br /&gt;
I don't know what to put here as we've already mentioned the issues and steps above.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests in [] which offers 100% coverage for the XXX Controller.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for [], &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
XXX controller coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155256</id>
		<title>CSC/ECE 517 Spring 2024 - E2439 Testing for view translation substitutor.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2439_Testing_for_view_translation_substitutor.rb&amp;diff=155256"/>
		<updated>2024-04-09T00:05:25Z</updated>

		<summary type="html">&lt;p&gt;Samason4: /* Model Overview &amp;amp; Test Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2439 Testing for view translation substitutor.rb==&lt;br /&gt;
&lt;br /&gt;
This wiki page is for the description of changes made in Spring 2024, CSC/ECE 517 for the E2439 Testing for view translation substitutor.rb assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source software project (OSS) using [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza is led by [https://www.csc.ncsu.edu/people/efg Dr. Edward Gehringer]. Expertiza allows students to create different teams and work on various assignments and projects. Also, students have the capability to peer review and evaluate each other's work. In Expertiza, instructors have the ability to create new assignments and edit already existing projects. The instructor can use a filter to narrow a list of subjects for students. Expertiza allows submissions from PDFs, wiki pages and URLs document types.&lt;br /&gt;
&lt;br /&gt;
==Project Objective==&lt;br /&gt;
This class (view_translation_substitutor.rb) is designed to automate substituting text within view templates with translation keys. Our objective is to create tests to cover various edge cases. Also, we must add detailed explanations for all the tests.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The code coverage for view_translation_substitutor.rb currently stands at 0%, indicating a need to enhance the test coverage, particularly by focusing on testing edge cases. According to the existing test file, some methods may be broken. Adopting TDD could be an effective strategy to address and repair these methods.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
* '''Task #1:''' Determine what view_translation_substitutor.rb does and when it is called.&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #2:''' Debug and fix substitute()&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #3:''' Write tests to cover the methods: substitute, process_directory, process_view, and process_translation&lt;br /&gt;
&lt;br /&gt;
* '''Tasks #4:''' Write further tests to cover edge cases.&lt;br /&gt;
&lt;br /&gt;
==Model Overview &amp;amp; Test Implementation==&lt;br /&gt;
The ViewTranslationSubstitutor class is designed to assist in the internationalization process of applications by substituting hardcoded text strings in view templates with dynamic translation calls. It processes a given locale hash, iterates through directories and view files, and replaces identified strings with translations from the locale hash. Additionally, it generates statistics regarding the substitutions made during the process.&lt;br /&gt;
&lt;br /&gt;
Method Summaries:&lt;br /&gt;
&lt;br /&gt;
'''substitute(locale)'''&lt;br /&gt;
&lt;br /&gt;
''Description:'' Processes the given locale hash by iterating through directories and view files, replacing hardcoded strings with translations, and generating statistics.&lt;br /&gt;
Parameters:&lt;br /&gt;
locale: A hash containing translation data organized by directory and view name.&lt;br /&gt;
&lt;br /&gt;
''Returns:'' None&lt;br /&gt;
&lt;br /&gt;
''Use Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
''Edge Cases'' &lt;br /&gt;
&lt;br /&gt;
# When .&lt;br /&gt;
&lt;br /&gt;
'''process_directory(dir_name, view_hash)'''&lt;br /&gt;
&lt;br /&gt;
Description: Processes a directory within the application, iterating through view files and replacing hardcoded strings with translations.&lt;br /&gt;
Parameters:&lt;br /&gt;
dir_name: Name of the directory being processed.&lt;br /&gt;
view_hash: Hash containing translation data for views within the directory.&lt;br /&gt;
&lt;br /&gt;
Returns: A hash containing statistics for each view within the directory.&lt;br /&gt;
&lt;br /&gt;
'''process_view(directory_name, view_name, translations)'''&lt;br /&gt;
&lt;br /&gt;
Description: Processes a specific view file, replacing hardcoded strings with translations and updating the file accordingly.&lt;br /&gt;
Parameters:&lt;br /&gt;
directory_name: Name of the directory containing the view file.&lt;br /&gt;
view_name: Name of the view file.&lt;br /&gt;
translations: Hash containing translation data for the specific view.&lt;br /&gt;
&lt;br /&gt;
Returns: A hash containing statistics for the translations made in the view file.&lt;br /&gt;
&lt;br /&gt;
'''process_translation(contents, key, val)'''&lt;br /&gt;
&lt;br /&gt;
Description: Processes translations within the contents of a view file, replacing hardcoded strings with dynamic translation calls.&lt;br /&gt;
Parameters:&lt;br /&gt;
contents: Contents of the view file as a string.&lt;br /&gt;
key: Key representing the translation key.&lt;br /&gt;
val: Value representing the translation text.&lt;br /&gt;
&lt;br /&gt;
Returns: A tuple containing a hash of statistics for the translations made and the updated contents of the view file.&lt;br /&gt;
&lt;br /&gt;
==Plan of Work==&lt;br /&gt;
We will begin by inserting some debug statements into the model and running expertiza in order to find out when the model runs and what it is accomplishing. Once finished, we will determine what is wrong with the main method of the model, substitute() and fix it. Then we will write tests to have 100% coverage of the model. After that, we will decide what edge cases may arise. Finally, we will write tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
Below is a UML diagram already uploaded in Expertiza database documentation for reader reference.&amp;lt;br&amp;gt;&lt;br /&gt;
INSERT UML DIAGRAM HERE&lt;br /&gt;
&amp;lt;!-- [[File:Review mappings imported.png|700px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
Not sure what to put here. Below is an example from another project.&lt;br /&gt;
&lt;br /&gt;
The Code present in review_mapping_helper can be improved by using design patterns to improve maintainability, readability, and flexibility.&lt;br /&gt;
Following are some design patterns that are suggested &lt;br /&gt;
&lt;br /&gt;
* Methods can be extracted into smaller, well maintained with just a single responsibility. This will promote code readability and promote code reuse.&lt;br /&gt;
&lt;br /&gt;
*The methods review_report_data, team_color, obtain_team_color, and others follow a common sequence of steps but allow for variation in some steps. Applying the Template Method Pattern can help define a common structure in a base method while allowing specific steps to be implemented in subclasses or overridden in derived methods.&lt;br /&gt;
&lt;br /&gt;
*Descriptive and short naming conventions are required so the methods and variables are self explanatory.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns should be followed for following code.&lt;br /&gt;
&lt;br /&gt;
====Work Plan====&lt;br /&gt;
&lt;br /&gt;
I don't know what to put here as we've already mentioned the issues and steps above.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
&lt;br /&gt;
*  app/models/view_translation_substitutor.rb&lt;br /&gt;
*  app/spec/models/view_translation_substituto_specr.rb&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
Testing is currently at 0%. We will first write tests to ensure coverage of each of the four methods in view_translation_substitutor.rb. Then we will add tests to cover the edge cases.&lt;br /&gt;
&lt;br /&gt;
====Demo Video====&lt;br /&gt;
INSERT VIDEO HERE&lt;br /&gt;
&lt;br /&gt;
====Using RSpec====&lt;br /&gt;
We implemented tests in [] which offers 100% coverage for the XXX Controller.&lt;br /&gt;
&lt;br /&gt;
====How to See Test Coverage====&lt;br /&gt;
Run RSpec for [], &amp;lt;code&amp;gt;sudo su&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yum install lynx&amp;lt;/code&amp;gt;,  then &amp;lt;code&amp;gt;lynx ./coverage/index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
The image below shows the test cases are passing as well as most of the code climate issues were resolved.&lt;br /&gt;
&lt;br /&gt;
XXX controller coverage = 100%&lt;br /&gt;
&lt;br /&gt;
INSERT IMAGE HERE&lt;br /&gt;
&amp;lt;!-- [[File:E2353-Test-Report.png|250px]] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
To be determined after project completion.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===Mentor===&lt;br /&gt;
Mustafa Olmez (molmez@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
Shandler Mason (samason4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ben Morris (bcmorri4@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Ray Wang (rwang32@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza GitHub]&lt;br /&gt;
# [https://github.com/CSC517-Project4/expertiza Project Repository]&lt;br /&gt;
# [LINK Github Project Board]&lt;br /&gt;
# [LINK Pull Request]&lt;br /&gt;
# [https://www.theodinproject.com/lessons/ruby-introduction-to-rspec RSpec]&lt;/div&gt;</summary>
		<author><name>Samason4</name></author>
	</entry>
</feed>